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:

 

Other JSP Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment