<c:url>标记格式的URL转换为字符串,并将其存储到一个变量。重写必要时,此标签会自动执行URL。 var属性指定将包含格式化的URL中的变量。
JSTL的URL标记是写在调用response.encodeURL()方法只是一种替代方法。唯一的真正优势是URL标记提供的是正确的URL编码,包括子param标签中指定的参数。
<c:url>标记具有以下属性:
属性 | 描述 | 必须 | 默认 |
---|---|---|---|
value | 根URL | Yes | None |
context | / followed by the name of a local web application | No | Current application |
var | Name of the variable to expose the processed URL | No | Print to page |
scope | Scope of the variable to expose the processed URL | No | Page |
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title><c:url> Tag Example</title> </head> <body> <a href="<c:url value="/jsp/index.html"/>">TEST</a> </body> </html>这将产生以下输出结果: