In this tutorial you will learn how to use the param element in a jsp page.
JSP param Element
In this tutorial you will learn how to use the param element in a jsp page.
param element in JSP is used to provide the additional data to the page on which you are transferring the control by invoking forward or include element. <jsp:param></jsp:param> element can be used to append the parameter to the request object.
Syntax
<jsp:param name="paramName" value="paramValue"/>
This element can be used with include or forward as :
Use with forward :
<jsp:forward page="forwardedPage"> <jsp:param name="paramName" value="paramValue" /> </jsp:forward>
Use with include :
<jsp:include page="includePage.jsp"> <jsp:param name="paramName" value="paramValue" /> </jsp:include>
Example :
jspParamExample.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP param Example</title>
</head>
<body>
<form method="get">
<table>
<tr>
<td>Name</td> <td><input type="text" name="name"/></td>
</tr>
<tr>
<td>Password</td> <td><input type="password" name="psw"/></td>
</tr>
<tr><td></td><td><input type="submit" value="submit"/></td></tr>
</table>
</form>
<%
String name= request.getParameter("name");
String psw= request.getParameter("psw");
if(psw!=null && psw.equals("devmanuals"))
{
%>
<jsp:forward page="Forwarded.jsp">
<jsp:param name="paramName" value="Devmanuals"/>
</jsp:forward>
<% } %>
</body>
</html>
Forwarded.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Forwarded Page</title>
</head>
<body>
<%
String value= request.getParameter("paramName");
if(value!=null)
{
%>
Value of the param (jsp:param)= <%= value %>
<% } %>
</body>
</html>
Output :
1. When you will execute the jspParamExample.jsp the output will be as :

2. When you will put the value in text boxes as 'devmanuals' and 'devmanuals' output will be as :

3. If every text box contains a value as above and click on submit button then the output will be as :


[ 0 ] Comments