I need to use some link as argument to <spring:message />
and use <c:set/>
for that. To have link relative to contextPath i use <c:url>
. Why using <c:url/>
in <c:set/>
inside like below doesn't 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 good:
<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 exactly something like that:
<c:set value='<a href="<c:url value="/x"/>">here</a>' var='doc1'/>
The <c:url> tag formats a URL into a string and stores it into a variable. This tag automatically performs URL rewriting when necessary. The var attribute specifies the variable that will contain the formatted URL. The JSTL url tag is just an alternative method of writing the call to the response.
It is used to set the result of an expression evaluated in a 'scope'. The <c:set> tag is helpful because it evaluates the expression and use the result to set a value of java. util. Map or JavaBean.
JSTL <c:url> Core Tag. <c:url> JSTL tag is used for url formatting or you can say url encoding. This is mainly used when we need to open a JSP page based on the user input or based on the value of a variable. It basically converts a relative url into a application context's url.
Put it in the tag body:
<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 well-formness:
<c:url var="url" value="/x" />
<c:set var="doc1"><a href="${url}">here</a></c:set>
<spring:message code="doc.link" arguments="${doc1}"/>
<c:url>
has an option to set the result to a variable, rather than outputting it. Just set the var
attribute.
<c:url value="..." var="doc1" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With