如何使用jstl在jsp的日历类型方法中获取日期设置?
我正在使用执行查询
select lastlevel as VERSION,name as DESCRIPTION,
TO_DATE(lastdate, 'DDMONYYYY_HH24:MI:SS') as RELEASEDATE
from mytable where rownum<=10
此处lastdate列为varchar类型
here the column lastdate is of varchar type
给出这样的结果
Version Release Date
1.0 2002-11-22
2.0 2003-02-08
我正在像这样设置以上查询的结果 这里的setLastDate是日历类型,所以我用
i am setting the result of the above query like this here setLastDate is of calender type,so i am setting the result of release date in the method like
if (rs.getString("VERSION") != null ) { bean.setLastLevel(rs.getString("VERSION").trim());
}
if (rs.getDate("RELEASEDATE") != null )
{
Calendar calendar = Calendar.getInstance();
calendar.setTime(rs.getDate("RELEASEDATE"));
bean.setLastDate(calendar);
}
正在像2003-02-08这样在bean中设置值. 最后,我将此结果bean添加到数组列表列表"中,例如 list.add(bean);
the value is being set in the bean like this 2003-02-08. at the end i am adding this result bean to an array list "list" like list.add(bean);
现在我希望在jsp中使用所有这些值.我正在使用spring mvc,所以我用arraylist"list"返回视图. 当我迭代jsp中的值时 像这样
now i want all this value in jsp. I am using spring mvc so i return view with the arraylist "list". when i am iterating the value in jsp like this
<c:forEach var="list" items="${list}">
<td valign="top">${list.lastLevel}</td>
<td valign="top">${list.lastDate}</td>
</c:forEach>
在jsp中,我没有得到日期,就像这样
in jsp instead of getting date i am getting like this
Version Release Date
1.0 java.util.GregorianCalendar[time=1037775600000,areFieldsSet=true,
areAllFieldsSet = true,lenient = true,zone = sun.util.calendar.ZoneInfo [id ="US/Arizona",offset = -25200000,dstSavings = 0,useDaylight = false,transitions = 12,lastRule = null] ,firstDayOfWeek = 1,minimumDaysInFirstWeek = 1,ERA = 1,YEAR = 2002,MONTH = 10,WEEK_OF_YEAR = 47,WEEK_OF_MONTH = 4,DAY_OF_MONTH = 20,DAY_OF_YEAR = 324,DAY_OF_WEEK = 4,DAY_OF_WEEK_IN_MONTH = 3,AM_PM = 0 = 0,HOUR_OF_DAY = 0,MINUTE = 0,SECOND = 0,MILLISECOND = 0,ZONE_OFFSET = -25200000,DST_OFFSET = 0]
areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="US/Arizona",offset=-25200000,dstSavings=0,useDaylight=false,transitions=12,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2002,MONTH=10,WEEK_OF_YEAR=47,WEEK_OF_MONTH=4,DAY_OF_MONTH=20,DAY_OF_YEAR=324,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=-25200000,DST_OFFSET=0]
2.0 java.util.GregorianCalendar[time=1044687600000,areFieldsSet=true,
areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="US/Arizona",offset=-25200000,dstSavings=0,useDaylight=false,transitions=12,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2003,MONTH=1,WEEK_OF_YEAR=6,WEEK_OF_MONTH=2,DAY_OF_MONTH=8,DAY_OF_YEAR=39,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=2,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=-25200000,DST_OFFSET=0]
请帮助我解决这个问题.我需要得到结果的日期.如何解决这个问题. 预先感谢.
please help me in solving this.I need to get the date as in result.How to resolve this. Thanks in advance.
使用
<td valign="top">${list.lastDate.time}</td>
它将在日历实例上调用getTime()
方法,该方法返回Date
实例
It will call getTime()
method on calendar instance which returns the Date
instance
最好不要使用与属性相同的var名称,而是将其命名为row
(或其他有意义的变量名),然后再命名为${row.lastDate.time}
It is preferable not to use same var name as the attribute, call it row
(or someother sensible variable name) instead and then ${row.lastDate.time}
<c:forEach var="row" items="${list}">
</c:forEach>
如果要自定义格式输出,则
if you want the custom format output then
添加
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
并像使用它
<fmt:formatDate pattern="yyyy-MM-dd" value="${list.lastDate.time}" />