Pergunta

In a spring-mvc app, I need a jsp page to have a url to another page which includes the local current date in the url. How do I accomplish this?

Here is the code I have so far, which does not work:

<jsp:useBean id="now" class="java.util.Date" scope="request" />
<fmt:formatDate value="${now}" pattern="MM.dd.yyyy" />
<spring:url value="/calendar?day=${now}" var="calendar_manageUrl"></spring:url>
<a href="${fn:escapeXml(calendar_manageUrl)}" class="btn btn-info" >Calendar</a>
Foi útil?

Solução

Did you mean to store the formatDate result

<fmt:formatDate value="${now}" pattern="MM.dd.yyyy" var="formatted" />

and then re-use it? Like so

<spring:url value="/calendar?day=${formatted}" var="calendar_manageUrl"></spring:url>

<fmt:formatDate> doesn't do anything to the Date object. A Date doesn't have a format. Printing it gives it a format. Formatting it gives it a format. You need to store and re-use the result of that formatting.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top