问题描述
TutorialPoint 具有c:url
标签的简单示例,如下所示:
TutorialPoint has a simple example of the c:url
tag that looks like this:
<%@ 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.htm"/>">TEST</a>
</body>
</html>
使用Chrome开发人员工具查看相应的渲染时,其渲染如下:
When looking at the corresponding rendering with Chrome's developer tooling it renders like this:
<a href="/jsp/index.htm">TEST</a>
所以c:url
标记似乎是多余的,但是我确定我遗漏了一些东西吗?
So the c:url
tag seems redundant, but I'm sure I'm missing something?
推荐答案
正如Tutorials Points所说,这是出于格式化的目的,用于放置 URL ,它可以存储在变量中.
As Tutorials Points says, It is for formatting purposes of the URL you put in and it can be stored in a variable.
示例如下:
<a href="<c:url value="/test.html"/>">TEST</a>
如果您单击 TEST (测试),它将转到页面test.html
.就那么简单.但是问题是<c:url value="/test.html"/>
的值是什么?
if you click TEST, it will go to page test.html
. simple as that. but the question is, what is the value of <c:url value="/test.html"/>
?
您认为值仅是/test.html
吗?
尝试进行测试,如下所示:
try to test it, like this:
<a href="<c:url value="/test.html" var="testvar" />">TEST</a> // testvar is where you put the url formatted by c:url
<c:out value="${testvar}"/> // you print what is the formatted url
答案将是项目的上下文文件夹以及您放入的 URL .
the answer will be the Context Folder of your project plus the URL you put in.
上下文/test.html将作为输出.
context/test.html will be the output.
我认为其目的是已经为URL
提供了context
(当前应用程序),而您只需要添加其余的URL
部分.
I think that its purpose is to have the context
(Current Application) already given to the URL
, and you only need to add the remaining URL
part.
这篇关于jstl的c:url标记的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!