URL in JSP Core Tag Library

What is "url" tag in JSP Core Tag Library?


The url tag of the core tag library can be used to apply appropriate url encoding and coversion rules for relative urls. This tag is also used to rewrite a url by adding the session ID only if the browser does not support cookies.


<c:url value="url" [context="externalContextPath"]
[var="var"] [scope="page|request|session|application"] />

In the above example the "var" attribute stores the url with its scope in "scope" attribute. The "context" attribute is used to add a context name prepended to the url.

Example :

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<form method="POST">
<input type="text" name="url" value="/coreurleg.jsp"/>
<input type="text" name="txt"/></td>
<input type="submit" value="Submit" name="submit" />
<c:if test="${pageContext.request.method=='POST'}">
<c:url value="${param.url}" var="url">
<c:param name="txt" value="${param.txt}"/>
<br/><b>The Rewritten URL is:</b>
<c:out value="${url}"/>


The Rewritten URL is: /test/coreurleg.jsp?txt=result

In the above example we have used just the relative url of the file "coreurleg.jsp", by using the "<c:url;" tags "<c:param" attribute we get complete url, along with the text entered in the page as "/test /coreurleg.jsp?txt=result."

Ask Questions

Ask Question