Extracting variable from jsp

Extracting variable from jsp

how to Write a java program which will be extracting the variables and putting them in an excel format?

View Answers

July 20, 2012 at 3:34 PM

The given code allow the user to enter some fields and using the POI API, these field values will get inserted into the excel file.

1)Create form.jsp

<html>
<body>
<form name="userform" method="post" action="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:
Extracting variable from jsp
Extracting variable from jsp  how to Write a java program which will be extracting the variables and putting them in an excel format?   The given code allow the user to enter some fields and using the POI API
Assigning a value to JSP variable from a bean class. - JSP-Servlet
Assigning a value to JSP variable from a bean class.  Hi, I want to know how we can assign value to a JSP variable from a Java Bean. I am using Struts, JSTL. Which tags should I use to assign the value. e.g Kindly
Advertisements
Extracting equation from any document
Extracting equation from any document  how can i extract equation from any word document?   Hello Friend, If you want to extract data from the word file, then visit the following link: Extract data from word document
How I get a variable from java script to use it in the scriptlet of jsp.
How I get a variable from java script to use it in the scriptlet of jsp.  Hi i want to get the tinyUrl value in the scriptlet of jsp. // Bit.ly API var url="http://cplive.com/dealDetail.do?method=displayDealDetail&
Converting jsp variable to java variable
Converting jsp variable to java variable  Hi how to convert java script variable to java variable on same jsp page
Extracting the audio from video without conversion
Extracting the audio from video without conversion  Hi, I have... is the command for extracting the original audio from video? Give me the example of extracting the audio from video without conversion. Thanks   Hi
Extracting position of a particular string from a PDF
Extracting position of a particular string from a PDF  I have a pdf form. I want to knw the exact position(location) of a particular string of that form. Using iText I have extracted all the string from the PDF form, but nt able
Extracting table from Access Database to Servlet
Extracting table from Access Database to Servlet  Sir, I have... show 900. I have written the query as : Select sum(h1) from expend where head_id...(); ResultSet res=stat.executeQuery("select SUM(ne) from expenditure1 where headid=H1
how to assign javascript variable value to a jsp variable
how to assign javascript variable value to a jsp variable  how to assign javascript variable value to a jsp variable
How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js?
How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js?  How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js? I set
JSP Create Variable
illustrate an example from 'JSP Create Variable'. To understand the example we create... JSP Create Variable          JSP Create Variable is used to create
JSP Variable in Javascript
that takes the defined variable from the jsp expression and display the message from... variable from the jsp expression "HelloWorld". The expression <%=str... JSP Variable in Javascript   
how to pass variable from simple java main class(not servlet) to the jsp page?
how to pass variable from simple java main class(not servlet) to the jsp page?  I have a simple Java class in which I invoke a call to a JSP page... from the simple Java class to the JSP page. How can I do that? Here is my
variable for cookie.setDomain - JSP-Servlet
variable for cookie.setDomain  I want to create a variable to use inside the following statement: cookie.setDomain(".mydomain.com"); Users will be hitting different sites using the same code for all. Any suggestions would
How to pass javascript variable in Scriplet of JSP?
How to pass javascript variable in Scriplet of JSP?  How can I assign the value of a javascript variable to a variable declared in jsp scriplet? Is it possible
store data from a variable in mysql?
store data from a variable in mysql?  sir last time asked you tell me how to retrieve data from a database mysql and store it in an int variable... of the calculation from an int variable into mysql in a new table of database. how
Sending query with variable - JSP-Servlet
page here userno--> variable which contains no. that is retrieved from.... The links page is not static one. Links page displays the contents from database and query should have a variable at the end. While using this variable we
Getting environment variable value from java
Getting environment variable value from java  Getting environment variable value from java
variable setting for servlet - JSP-Servlet
variable setting for servlet  how to set environment variable and class path variable for servlet and to compile servlet files i am using tomcat 6.0  Hi Friend, Please visit the following links: http
onclick pass variable - JSP-Servlet
onclick pass variable  on button onclick event pass variable and print in textbox in same page... i want to pass value of variable at onclick event of button and also want to print it in textbox in same page....  Hi
How to Assign struts2 property to jsp variable
.   But i wants to assign the value to jsp variable   I wants to assign to jsp variable   wants to assign <s:property value="fname" /> to jsp variable
Creating a Local Variable in JSP
Creating a Local Variable in JSP          In jsp when we have to create a method or variable we usually declare it inside the declaration tag. If we declare
Getting Json data from servlet to javascript variable
Getting Json data from servlet to javascript variable  How do i get json data from my servlet on to a variable in javascript n bind the data to display onto sigma grid.Has anyone Idea how to do
Redirecting the output of an expression to a variable - JSP-Servlet
Redirecting the output of an expression to a variable  I want to redirect the output of to a variable defined in variable.jsp. What is the syntax...' file: Create another jsp file 'get.jsp' to get the output: Thanks
retrieve data from mysql database and store it in a variable ?
retrieve data from mysql database and store it in a variable ?  sir... to store that data in int variable. how to do this ?   Here is an example that retrieve the integer values from the database and stored in the integer
Assign value from a <bean:write> tag to a variable
Assign value from a tag to a variable  I am calling a stored procedure from JSP page which needs an input parameter. This input parameter needs to get the value from bean write tag . How can i do that ?   Please go
Creating a Local Variable in JSP
Creating a Local Variable in JSP      In jsp when we have to create a method or variable we usually declare.... This works like a instance variable.  Now consider a situation where we have
Java from JSP - JSP-Servlet
Calling Java from JSP  Does anyone have an example of Calling Java from JSP
how to call jsp variable through servlet
how to call jsp variable through servlet  Hi deepak; i am posting some peace of code. and i need to call jsp varable <%=f%> through servlet so that it can call the downlode.jsp page. String f = "C:/temp/View HR
connect to the database from JSP
connect to the database from JSP  How do you connect to the database from JSP?   A Connection to a database can be established from a jsp page by writing the code to establish a connection using a jsp scriptlets
calling servlet from jsp
calling servlet from jsp  how to call a servlet from jsp
RADIO FROM JSP TO ACTION.
RADIO FROM JSP TO ACTION.  Hi frds, how to get the selected multiple radio button values from jsp to action
unable to get value returned from javascript variable in page
unable to get value returned from javascript variable in page  Hi, I... jsp page..what i want is to store the value returned from the js function... the value of the radio button from fisrt page to be stored in a variable so
Calling from JSP
Calling from JSP  how can we call a class file from JSP   Hi, Do you want to call a servlet or a Java Bean through JSP? Please clarify this. For more information, visit the following link: JSP Tutorials Thanks
convert javascript var to java variable - JSP-Servlet
convert javascript var to java variable  hi how to conver javascript var to java variable?  Hi Friend, We are providing you two ways: 1)a.jsp: function call(){ var name = "roseindia
How to Assign struts2 property to jsp variable
How to Assign struts2 property to jsp variable  In Struts2 <s:property value='count'/> I wants to assign <% int count = %><s... visit the following link: Assign struts 2 property to JSP The above link
pdf generate from jsp
pdf generate from jsp  how do i generate a pdf using jsp that should query the data from the database and write it into a pdf and download the same
calling one jsp from another jsp page
calling one jsp from another jsp page  need coding for calling one jsp from another jsp including the xml file.Its urgent
How do I read a variable from a file in shell script
How do I read a variable from a file in shell script  Hi, In my... to read some of the variables from other file and then use this in spark submit command. How do I read a variable from a file in shell script and then use
Navigate from jsp to servlet - JSP-Servlet
Navigate from jsp to servlet   Hi Friends, Sample code for Navigating a page from jsp to servlet. Thanks
how to call the array variable in scriptlet from javascript function
how to call the array variable in scriptlet from javascript function  This is the scriptlet code:- <% String[] abc={"saab","volvo","bmw","Benz","Porsche","Jaguar"}; %> Actually i want the array variable one by one
non static variable cannot be referenced from static context
non static variable cannot be referenced from static context  public class Add{ int foo=7; int bar=8; public int add(int x,int y... "non static variable cannot be referenced from static context". How to solve
How to pass variable from one class to another in java
How to pass variable from one class to another in java  How to pass variable from one class to another in java?   Example: public class... and variable through by calling Class1 getter methods
non static variable cannot be referenced from static context
non static variable cannot be referenced from static context  public class Add{ int foo=7; int bar=8; public int add(int x,int y){ int z=x+y; System.out.println(z); return z; }//add
printing records from jsp - JSP-Servlet
printing records from jsp  Hi Plz tell me how to printing out pages from jsps with page numbers Thank you  Hi friend, For paging in Jsp visit to : http://www.roseindia.net/jsp/paging.shtml http
how to call jsp from flex
how to call jsp from flex  Plz help me out to get JSP from FLEX.... I need your help.... Thanks for future
how to call jsp from flex
how to call jsp from flex  hi, i want to know that how can i call a FLEX from JSP. . A good Example will be appreciated
Update Database from jsp
Update Database from jsp   I want to update my oracle database column from a text box ,so whenever I input some text value in the text box and click UPDATE button the database field should be updated . I have a drop down menu
ArrayList from JSP to Servlet - JSP-Servlet
ArrayList from JSP to Servlet  Hi, I have an arraylist declared in a scriplet in a jsp page. how can i access the arraylist in a servlet which... should it be declared in jsp and in servlet. do i need to do any casting
How to access the database from JSP?
How to access the database from JSP?  Hi, What is the process of accessing the database from JSP page? Thanks   Hi, In the JSP program... database from JSP which explains you how to access the database by embedding

Ads