<c:param> JSTL tag is mostly used with <c:url> and <c:redirect> tags. Basically it adds parameter and their values to the output of these tags. In this tutorial we will see how the <c:param> tag can be used with <c:url> and <c: redirect> tags.
Syntax:
<c:param name="parameter_name" value="parameter_value"/>
Attributes of <c:param> tag
- name: To specify the name of the parameter.
- value: To specify the value of the parameter.
Example of <c:param>
In this example we are using <c:param> tag for adding parameters to the resultant URL.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>JSTL c:param Tag Example</title> </head> <body> <c:url value="/mypage.jsp" var="completeURL"> <c:param name="Id" value="736"/> <c:param name="user" value="chaitanya"/> </c:url> ${completeURL} </body> </html>
Output:
Example 2: <c:param> use in <c:redirect> tag
Here we are passing parameters along with the redirect url using <c:param> tag and then we are displaying those parameters on the redirected page using param variable of expression language.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>c:param Example2</title> </head> <body> <c:redirect url="/display.jsp" > <c:param name="UserId" value="222"/> <c:param name="UserName" value="ChaitanyaSingh"/> </c:redirect> ${completeURL} </body> </html>
display.jsp
USER ID IS: ${param.UserId} USER NAME IS: ${param.UserName}
Output:
Krishna says
Can c:param have a dynamic value. Say ${test}