如何使用< spring:url/>带有< a>标签? [英] How to use <spring:url /> with an <a> tag?

查看:251
本文介绍了如何使用< spring:url/>带有< a>标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在<a>标记内使用<spring:url value="/something" />吗?

Can I use <spring:url value="/something" /> inside of an <a> tag?

推荐答案

 <spring:url value="/something" var="url" htmlEscape="true"/>
 <a href="${url}">...</a>

但是您也可以使用c:url

But you an also use c:url

 <c:url value="/something" var="url"/>
 <a href="<c:out value='${url}'/>">...</a>

c:urlspring:url之间的一个重要区别是,c:url不对创建的URL进行html编码.但是对于有效的URL,URL参数之间的&必须为&amp;.因此,您需要c:out对其进行转义. -在spring:url中,您已经包含此功能(如果我理解正确的文档).

The one important difference between c:url and spring:url is, that c:url does not html encode the created url. But for a valid url the & between the url parameters must be a &amp;. So you need the c:out to escape it. -- In spring:url you have this functionality already included (if I understand the documentation correct).

命名空间:

  • xmlns:spring="http://www.springframework.org/tags"
  • xmlns:c="http://java.sun.com/jsp/jstl/core"
  • xmlns:spring="http://www.springframework.org/tags"
  • xmlns:c="http://java.sun.com/jsp/jstl/core"

查看全文

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