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:
Posted on: February 9, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles