English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The <c:url> tag formats the URL into a string and then stores it in a variable.
This tag will automatically rewrite the URL when needed.
The var attribute is used to store the formatted URL.
The <c:url> tag is an optional method used to call the response.encodeURL() method. Its real advantage lies in providing appropriate URL encoding, including parameters specified in <c:param>.
<c:url var="<string>" scope="<string>" value="<string>" context="<string>"/>
The <c:url> tag has the following attributes:
Attribute | Description | Is Necessary | Default Value |
---|---|---|---|
value | Base URL | Yes | None |
context | The Name of Local Network Application | No | Current Application |
var | The Variable Name Representing URL | No | Print to page |
scope | The Scope of var Attribute | No | Page |
<%@ 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<c:url> Example <Demo</h1> <a href="<c:url value="http://www.oldtoolbag.com"/>"> This link is generated by the <c:url> tag. </a> </body> </html>
Visit the above page through a web browser and then view the source code or press F12 View