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

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 ){
}
%>









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
Hi how to transfer table data from html page to excel sheet by using javascript .
How to export web page to excel using java or jsp or servlets
How to export data from html to excel sheet by using java
Html form using JavaScript to display the table content
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
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 load pdf on html
How to retrieve array values from html form to jsp?
dispalying arraylist values in table form
how to load a table of data from oracle, to a jsp page using hashmap.
how to read values from excel sheet and compare with database using jsp
how to write a jsp form using html
convert html to excel using jsp
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
Printing Values of Resultset to Html Table
how to save html form data into .csv file using only jsp.
how to use Excel Templet to write excel file using java.
Hiding form values using ajax
how to use Excel Template to write excel file using java
Html form validation using jquery
inserting all the values in a html table column
how to create an excel file using java
How to read a rows which have a values in a excel file using apache poi - JSP-Servlet
How to design a form using java?
How to Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database(MySql)?
HTML form validation using jquery
How to populate an HTML table using jstl code - Spring
problem in linking the html page using servlets
form values in java script - Struts
form based file upload using servlets
servlet7
servlet5
servlet3
servlet4
servlet2
example of 1700 bir form using html
servlet6
servlet6
How to values from xml using java?
How to export data from jsp to excel sheet by using java
How to create simple HTML Form?
how html tags are extracted using java?
how html tags are extracted using java?
call json object using url and represent in html tabular form

Ads