<c:url> Tag
The <c:url> tag formats a URL into a string and stores it in a variable.
This tag automatically rewrites the URL when needed.
The var attribute is used to store the formatted URL.
The <c:url> tag is just an optional way to call the response.encodeURL() method. Its real advantage is that it provides proper URL encoding, including parameters specified in <c:param>.
Syntax
<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 | The name of the local web application | no | Current application |
| var | Variable name representing the URL | no | Print to page |
| scope | The scope of the var attribute | no | Page |
Examples
<%@ 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 标签实例</title>
</head>
<body>
<h1><c:url>实例 Demo</h1>
<a href="<.html"http://www.example.com"/>">
这个链接通过 <c:url> 标签生成。
</a>
</body>
</html>
Access the above page through a browser, then view the source code, and it will display as follows:

Other Extensions
JSP Standard Tag Library