[英]how to separate values in variable from fortokens in jstl
I'm stuck on assigning value to a variable
using forTokens
of JSTL
我被困在使用
JSTL
forTokens
向variable
forTokens
<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"
字符串日=“ 19”
String month = "April"
字符串月份=“四月”
String year = "2014"
字符串年份=“ 2014”
from ${values}
which is like Array
来自
${values}
,就像Array
Updated: 更新:
In JSP I added the following code: 在JSP中,我添加了以下代码:
<%--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: 在我的
pom.xml
我具有以下依赖关系:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.