Using c: url in c: set

I need to use some link as an argument for <spring:message />and use for this <c:set/>. To have a link regarding contextPath, I use <c:url>. Why is the use <c:url/>in the <c:set/>inside, as shown below, does not work?

<c:set value='<c:url value="/x"/>' var='doc1'/>
<spring:message code="doc.link" arguments="${doc1}"/> <%-- ${doc1} is empty --%>

Simlar using <a href/>works well:

<c:set value='<a href="/fullurl/x">here</a>' var='doc1'/>
<spring:message code="doc.link" arguments="${doc1}"/>

messages.properties:

doc.link = Doc is {0}

EDIT I need to work just like this:

<c:set value='<a href="<c:url value="/x"/>">here</a>' var='doc1'/>
+5
source share
3 answers

Put it in the body of the tag:

<c:set var="doc1"><a href="<c:url value="/x" />">here</a></c:set>
<spring:message code="doc.link" arguments="${doc1}"/>

Or, if you want XML validity:

<c:url var="url" value="/x" />
<c:set var="doc1"><a href="${url}">here</a></c:set>
<spring:message code="doc.link" arguments="${doc1}"/>
+13
source

<c:url>has the ability to set the result to a variable, rather than displaying it. Just set the attribute var.

<c:url value="..." var="doc1" />
+4

:

<c:url var="myURL" value="/x" />
<spring:message code="doc.link" arguments="${myURL}" />

doc.link = Doc is {0}, {0} , doc.link = Doc is :

<spring:message code="doc.link" /><a href="<c:url value="/x"/>">here</a>

, !

+3

All Articles