JSTL c:url Core Tag

The JSTL Core Tag is used to format or encode a url into a string variable. This variable can be used anywhere in the jsp instead of using url directly.
Syntax:

c:url tag attributes:

AttributeDescriptionRequired
valueIt specify the base URL.Yes
context/ followed by the name of a local web application.No
varName of the variable to expose the processed URL.No
scopeScope of the variable to expose the processed URL.No

Example:

test.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 
<html>
 <head>
  <title>c:url JSTL core tag example</title>
 </head>
 <body>
  <c:url value="/hello.jsp" var="helloUrl"/>
  <h4><a href="${helloUrl}">Click here</a></h4>
 </body>
</html>
hello.jsp
<html>
 <head>
  <title>c:url JSTL core tag example</title>
 </head>
 <body>
  <h3>This is a c:url JSTL core tag example.</h3>
 </body>
</html>
web.xml
<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list> 
 
</web-app>

Output:


Click on the link.


No comments: