Facebook Twitter LinkedIn RSS
 
 
Home » JSP » How to pass a variable from a JSP file to another

How to pass a variable from a JSP file to another

Here I am explaining the simple procedure of passing variables from a JSP page to another. One easy way is to pass them through a form as hidden variables. For example, I have the variable with name “parameter1″ and value and I want to pass it from page1.jsp to page2.jsp. On the form of page1.jsp I am writing the following:

<form method="post" action="page2.jsp">
<table>
....
<tbody><tr>
<td><input name="parameter1" value="<%=" type="hidden">></td>
</tr>
<input name="Submit" value="Done" onclick="Submit()" type="button">
<input name="Reset" value="Cancel" type="reset">
</tbody></table>

Now on page2.jsp I can access the “parameter1″ with the following statement:

HttpServeletRequest req;
req.getParameter("parameter1");

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>