how to load values of html form into an excel table using java servlet?

Ads
 

how to load values of html form into an excel table using java servlet?

i have written a java servlet program, which has a html form to be filled. after filling the form the servlet generates a receipt and the values should be loaded into an excel table automatically. i have created a dsn for excel table ,but my program is working till generation of receipt and the values are not loading into excel table. would you help me in solving this problem?

View Answers

March 13, 2012 at 4:55 PM

1)Create form.html

<html>
<body>
<form name="userform" method="post" action="http://localhost:8080/examples/excelFile.jsp">
<table>
<tr><td>Enter First Name:</td><td><input type="text" name="firstName"></td></tr>
<tr><td>Enter Last Name:</td><td><input type="text" name="lastName"></td></tr>
<tr><td>Enter User Name:</td><td><input type="text" name="userName"></td></tr>
<tr><td>Enter Address:</td><td><input type="text" name="address"></td></tr>
<tr><td>Enter Email ID:</td><td><input type="text" name="email"></td></tr>
<tr><td>Enter DOB:</td><td><input type="text" name="dob"></td></tr>
<tr><td><input type="submit" value="Export to excel"></td></tr>
</table>
</form>
</body>
</html>

2)Create excelFile.jsp

<%@page import="java.io.*"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%
String value1=request.getParameter("firstName");
String value2=request.getParameter("lastName");
String value3=request.getParameter("userName");
String value4=request.getParameter("address");
String value5=request.getParameter("email");
String value6=request.getParameter("dob");
try{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Excel Sheet");
HSSFRow rowhead = sheet.createRow((short)0);
rowhead.createCell((short) 0).setCellValue("First Name");
rowhead.createCell((short) 1).setCellValue("Last Name");
rowhead.createCell((short) 2).setCellValue("User Name");
rowhead.createCell((short) 3).setCellValue("Address");
rowhead.createCell((short) 4).setCellValue("E-mail Id");
rowhead.createCell((short) 5).setCellValue("Date Of Birth");

HSSFRow row = sheet.createRow((short)1);
row.createCell((short)0).setCellValue(value1);
row.createCell((short)1).setCellValue(value2);
row.createCell((short)2).setCellValue(value3);
row.createCell((short)3).setCellValue(value4);
row.createCell((short)4).setCellValue(value5);
row.createCell((short)5).setCellValue(value6);
FileOutputStream fileOut = new FileOutputStream("c:\\File.xls");
wb.write(fileOut);
fileOut.close();
out.println("Data is saved in excel file.");
}catch ( Exception ex ){
}
%>

Ads









Related Tutorials/Questions & Answers:
how to load values of html form into an excel table using java servlet?
how to update values of a html form into an excel table using java servlets?
Advertisements
How to export data from html to excel sheet by using java
How to export the table content from an webpage to excel using java?
How to export the table content from an webpage to excel using java?
How to export web page to excel using java or jsp or servlets
How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java
Hi how to transfer table data from html page to excel sheet by using javascript .
Html form using JavaScript to display the table content
how to load pdf on html
how to load a table of data from oracle, to a jsp page using hashmap.
how to use Excel Templet to write excel file using java.
How to retrieve array values from html form to jsp?
how to create an excel file using java
how to use Excel Template to write excel file using java
how to read values from excel sheet and compare with database using jsp
How to design a form using java?
dispalying arraylist values in table form
how to write a jsp form using html
how to display values from database into table using jsp
how to pass form values from javascript of html page to jsp page
excel parsing and print data in the form of table
how to save html form data into .csv file using only jsp.
convert html to excel using jsp
How to read a rows which have a values in a excel file using apache poi - JSP-Servlet
Printing Values of Resultset to Html Table
How to export data from jsp to excel sheet by using java
How to populate an HTML table using jstl code - Spring
How to Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database(MySql)?
inserting all the values in a html table column

Ads