Easy Tutorial
❮ Jstl Sql Setdatasource Tag Jstl Core Set Tag ❯

<c:url> Tag

JSP Standard Tag Library

The <c:url> tag formats a URL into a string and stores it in a variable.

This tag automatically rewrites the URL when necessary.

The var attribute is used to store the formatted URL.

The <c:url> tag is an alternative method to calling the response.encodeURL() method. Its real advantage lies in providing proper URL encoding, including parameters specified in <c:param>.

Syntax

&lt;c:url
  var="<string>"
  scope="<string>"
  value="<string>"
  context="<string>"/>

Attributes

The <c:url> tag has the following attributes:

Attribute Description Required Default Value
value Base URL Yes None
context Name of the local web application No Current application
var Variable name representing the URL No Print to page
scope Scope of the var attribute No Page

Example

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>c:url Tag Example</title>
</head>
<body>
    <h1>&lt;c:url&gt; Example Demo</h1>
    <a href="<c:url value="http://www.tutorialpro.org"/>">
     This link is generated by the &lt;c:url&gt; tag.
    </a>
</body>
</html>

When accessing the above page through a browser and viewing the source code, it displays as follows:


JSP Standard Tag Library

❮ Jstl Sql Setdatasource Tag Jstl Core Set Tag ❯