Search code examples
springjspjsp-tags

Spring JSP variable not assigned


I have in my JSP page code like this:

<spring:url value="" var="url"/>
<a href="<c:url value="/change_locale?locale=EN&current=${url}" />">EN</a>  

And issue is that parameter url in link is always set to empty String.I would expect that if I type url like localhost:8080/test the url variable will hold this value and it will be replaced in link so it would look like /change_locale?locale=EN&current=test. However it is always generated like /change_locale?locale=EN&current=.What I am doing wrong? Best regards


Solution

  • In

    <spring:url value="" var="url"/>
    

    Your value value is the empty String. Because of this, the URL is relative.

    Spring uses UrlTag to construct the value from a <url> tag. You'll want to take a look at its createUrl method in the source code if you're curious.

    In this case, it will generate a value that is the empty String and store it in a page scope attribute named url. That's what you get when rendering

    ${url}