Java jstl core tag param
The JSTL <c:param>
tag is used to add parameters to a URL or form submission in a JSP page. This tag is typically used in conjunction with other tags, such as <c:url>
and <c:forEach>
, to generate dynamic links and forms based on the state of some variable or condition.
The basic syntax for the <c:param>
tag is as follows:
<c:param name="parameterName" value="parameterValue" />
The name
attribute of the <c:param>
tag is used to specify the name of the parameter, while the value
attribute is used to specify the value of the parameter. Both attributes are required.
Here's an example that shows how to use the <c:param>
tag to add a parameter to a URL:
<c:url value="/my-page.jsp"> <c:param name="id" value="${item.id}" /> </c:url>
In this example, the <c:url>
tag is used to generate a URL for a page called "my-page.jsp". The <c:param>
tag is then used to add a parameter called "id" with a value of the current item's ID.
The resulting output of this code will be something like:
/my-page.jsp?id=123
Note that the <c:param>
tag can also be used to conditionally include or exclude parameters based on the value of some expression. For example, you could use the <c:if>
tag to include a parameter only if a certain condition is met:
<c:url value="/my-page.jsp"> <c:param name="id" value="${item.id}" /> <c:if test="${showDetails}"> <c:param name="details" value="true" /> </c:if> </c:url>
In this example, the <c:if>
tag is used to conditionally include a parameter called "details" with a value of "true" if the "showDetails" variable is true. Otherwise, the parameter will not be included in the URL.