jsp:param standard action examples
- Details
- Written by Nam Ha Minh
- Last Updated on 22 July 2019 | Print Email
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.
Syntax of JSP param action:
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 param action Examples:
- Use <jsp:param> within <jsp:include> action:
<jsp:include page="header.jsp" > <jsp:param name="language" value="english" /> <jsp:param name="country" value="USA" /> </jsp:include>
Access the parameters in the included page:Language: ${param.language} Country: ${param.country} - Use <jsp:param> within <jsp:forward> action:
<jsp:forward page="login.jsp" /> <jsp:param name="username" value="Tom"/> </jsp:forward>
Access the parameters in the forwarded page:Username: ${param.username} - Use <jsp:param> within <jsp:params> element of <jsp:plugin> action:
<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");
Other JSP actions:
- jsp:include standard action examples
- jsp:forward standard action examples
- jsp:plugin, jsp:params and jsp:fallback actions examples
Other JSP Tutorials:
- Summary of EL operators with examples
- Java Servlet and JSP Hello World Tutorial with Eclipse, Maven and Apache Tomcat
- How to handle exceptions in JSP
- How to list records in a database table using JSP and JSTL
- How to create dynamic drop down list in JSP from database
- Sending e-mail with JSP, Servlet and JavaMail
About the Author:
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.
Comments