Java 如何在jstl中将变量中的值与Fortoken中的值分开
我一直在使用Java 如何在jstl中将变量中的值与Fortoken中的值分开,java,jsp,jstl,Java,Jsp,Jstl,我一直在使用JSTL的forTokens为变量赋值 代码 现在我想知道如何获得: String day=“19” String month=“四月” 字符串年份=“2014” 从${values}开始,类似于数组更新: 在JSP中,我添加了以下代码: <%--You can use your date instead of this--%> <% pageContext.setAttribute("date", new Date()); %> <fmt:fo
JSTL的forTokens
为变量赋值
代码
现在我想知道如何获得:
String day=“19”
String month=“四月”
字符串年份=“2014”
从${values}
开始,类似于数组更新:
在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}"/>
在mypom.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>
javax.servlet
javax.servlet-api
3.0.1
假如
javax.servlet.jsp
javax.servlet.jsp-api
2.3.0
假如
javax.servlet
jstl
1.2
这给了我javax.el.ELException:无法将2014年4月19日的java.lang.String类转换为java.util.Date类
超级用户,请检查另一种方法:等人
非常感谢您的时间,但很抱歉其他
回答我的问题
。任何方式快乐编码
;-)上面的code
按我的要求工作。非常感谢伙计
,你刚刚救了我的命,我很困惑是谁否决了这个-P
<%--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}"/>
The day is: 19
The month is: April
The year is: 2014
<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>