Passing Parameters to Another JSP Page
By using the include action we can pass the parameters to another jsp page. We can do this by doing using the <jsp:param>. This tag is used as a child tag. It can temporarily override a request parameter or it can temporarily introduce a new request parameter when calling a jsp page. This param tag can be attached to a query string by adding ?param1=name1¶m2=name2 at the last of URL string.
In this program we are retrieving the parameter by using the getParameter("String str"). This method can be used to capture the values in the jsp post from the html form or the jsp page.
The code of the program is given below:
<html> <head></head> <body> <jsp:include page="RetrievingParameters.jsp" > <jsp:param name="name2" value="James" /> <jsp:param name="name3" value="Bill" /> </jsp:include> Pass the value: Name1: <%= request.getParameter("name1") %><br> Name2: <%= request.getParameter("name2") %><br> Name3: <%= request.getParameter("name3") %><br><br> </body> </html> |
Retriever: Name1: <%= request.getParameter("name1") %><br> Name2: <%= request.getParameter("name2") %><br> Name3: <%= request.getParameter("name3") %><br> |
The output of the program is given below: