jstl的c:url标记的目的是什么? [英] What is the purpose of jstl's c:url tag?

查看:74
本文介绍了jstl的c:url标记的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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标记的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆