Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

How to use <spring:url /> with an <a> tag?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
 <spring:url value="/something" var="url" htmlEscape="true"/>
 <a href="${url}">...</a>

But you an also use c:url

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

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).

Namespaces:

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

http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/spring.tld.html#spring.tld.url


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...