BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

JSTL <c:param> Core Tag

By Chaitanya Singh | Filed Under: JSTL

<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:

c-param-example

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:

c-param-example2

Comments

  1. Krishna says

    January 5, 2017 at 11:32 PM

    Can c:param have a dynamic value. Say ${test}

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

JSTL Core Tags

  • c:out
  • c:set
  • c:remove
  • c:if
  • c:choose
  • c:when
  • c:otherwise
  • c:catch
  • c:import
  • c:forEach
  • c:forTokens
  • c:param
  • c:url
  • c:redirect
JSTL Functions
  • fn:contains()
  • fn:containsIgnoreCase()
  • fn:indexOf()
  • fn:escapeXML()
  • fn:join() & fn:split()
  • fn:length()
  • fn:startsWith()
  • fn:endsWith()
  • fn:substring()
  • fn:substringAfter()
  • fn:substringBefore()
  • fn:trim()
  • fn:toUpperCase()
  • fn:toLowerCase()
  • fn:replace()

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap