The <jsp:param> action is used to provide information in the form of key/value pair. This action can be used as direct child element of the following actions: <jsp:include>, <jsp:forward> and <jsp:params> (which is a child element of the <jsp:plugin> action). The JSP compiler will issue a translation error if this element is used elsewhere.
The <jsp:param> action has pretty simple and straightforward syntax:
<jsp:param name="paramName" value="paramValue" />
Both of the attributes paramNameand paramValue are mandatory, and the paramValue can accept a runtime expression.
For the <jsp:include> and <jsp:forward>actions, the parameters will be added to the request object of the included page and forwarded page.
<jsp:include page="header.jsp" >
<jsp:param name="language" value="english" />
<jsp:param name="country" value="USA" />
</jsp:include>Language: ${param.language}
Country: ${param.country}
<jsp:forward page="login.jsp" />
<jsp:param name="username" value="Tom"/>
</jsp:forward>Username: ${param.username} <jsp:plugin
type="applet"
code="net.codejava.applet.MyApplet.class"
codebase="html">
<jsp:params>
<jsp:param name="username" value="Tom" />
</jsp:params>
</jsp:plugin>
Access the parameters in the applet:
String username = getParameter("username");
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.