I'm stuck on assigning value to a variable
using forTokens
of JSTL
<c:forTokens items="${row.date}" delims="/" var="values">
<c:set var="date" value="${values}"></c:set>
<c:out value="${date }"></c:out>
</c:forTokens>
through the above code I get some thing like :
19 April 2014
Now I want to know how to get :
String day = "19"
String month = "April"
String year = "2014"
from ${values}
which is like Array
Updated:
In JSP I added the following code:
<%--You can use your date instead of this--%>
<% pageContext.setAttribute("date", new Date()); %>
<fmt:formatDate value="${date}" pattern="dd" var="day" /></p>
The day is: <c:out value="${day}"/>
<fmt:formatDate value="${date}" pattern="MMMM" var="month" /></p>
The month is: <c:out value="${month}"/>
<fmt:formatDate value="${date}" pattern="yyyy" var="year" /></p>
The year is: <c:out value="${year}"/>
And it works:
The day is: 19
The month is: April
The year is: 2014
In my pom.xml
I have the following dependencies:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<c:forTokens items="${row.date}" delims="/" var="values" varStatus="status">
<c:if test="${status.index == 0}">
<c:set var="day" value="${values}"></c:set>
</c:if>
<c:if test="${status.index == 1}">
<c:set var="month" value="${values}"></c:set>
</c:if>
<c:if test="${status.index == 2}">
<c:set var="year" value="${values}"></c:set>
</c:if>
</c:forTokens>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.