Home Jsp Simple-jsp-example Passing Parameters using

Related Tutorials


 
 

Share on Google+Share on Google+

Passing Parameters using

Advertisement
Request parameters can be passed by using

Passing Parameters using <jsp: param>

        

Request parameters can be passed by using <jsp: param>

This tag contains two attributes: 1) name 2) value.  This tag is mostly used as a child tag enclosed inside any  action tag.  The tag which is enclosing this tag in this example is <jsp: forward >. This tag forwards the request object containing the client request from one jsp file to another file. The targeted file can be a Html file, jsp file or any other servlet file. This tag contains only one parameter page = "relativeURL". This relativeURL represents the file to which the request will be forwarded. 

We can pass the parameter names and values to the forwarded file by using a <jsp: param> tag. We can use multiple <jsp: param> tag inside the <jsp: forward> tag if we have to pass more than one parameter to the target file. The name attribute specifies the parameter name and takes a string literal as a value. These parameters are evaluated at request time. 

In this example we are passing a parameters to a file by using <jsp: forward> tag. Inside this tag we have used the tag <jsp: param>. This tag is used to pass the name and values to the targeted file. These parameters will be retrieved by the targeted file by using request.getParameter() method. In this way we can pass and retrieve the parameters. 

The code of the program is given below:

 

 

<html>
<head>
<title></title>
</head>
<body>
<jsp: forward page="ssParameters.jsp">
  <jsp: param name="myParam" value="Amar Patel"/>
  <jsp: param name="Age" value="15"/>
</jsp: forward>
</body>
</html>

 

This page had a parameter forwarded to it:<br>
<b>Name:</b> <%= request.getParameter("myParam") %><br>
<b>Age:</b> <%= request.getParameter("Age") %>

Output of the Program:

 

Download this example.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 9, 2008

Related Tutorials

Discuss: Passing Parameters using   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:4
kedar pethe
April 16, 2011
Thanks

Excellent website. Full focused information. Keep it up!!!!!
Saurabh
March 3, 2012
Dynamic values for parameters

Can the parameter values be made dynamic, such that they are enclosed in <% %> and a variable be passed.
sivakumar
June 18, 2012
why end tag for jsp:param

i like to get the need of </jsp:param> tag usage
Jose
October 12, 2012
A question

I have a question, I wanna pass an object, for example a map, using jsp:param, is it possible? how can I do it?
DMCA.com