Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 433
213897 Avatar asked Feb 15 '11 17:02

213897


People also ask

What are the tags in Spring?

The Spring MVC form tags are the configurable and reusable building blocks for a web page. These tags provide JSP, an easy way to develop, read and maintain. The Spring MVC form tags can be seen as data binding-aware tags that can automatically set data to Java object/bean and also retrieve from it.

Where do I put html files in spring boot?

In the index. html file we have a link that invokes a response from the web application. The file is located in the src/main/resources/static directory, which is a default directory where Spring looks for static content.

What is Spring MVC form tag library?

Spring's form tag library is integrated with Spring Web MVC. It gives the tag access to the command object and reference data the controller deals with. The implementation of all the tags in the Spring tag library is available in org. springframework.


1 Answers

 <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

like image 56
Ralph Avatar answered Oct 02 '22 09:10

Ralph