1

我想用明天的日期(服务器端,而不是客户端)设置日期选择器。

我从jsp尝试了这个jquery datepicker set minDate和maxDate,并添加了:

<% 
try { 
    Date now = new Date();  
    Calendar cal = Calendar.getInstance();  
    cal.setTime(now);  
    cal.add(Calendar.DAY_OF_YEAR, 1); 
    Date tomorrow = cal.getTime(); 
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

}   catch (Exception e) {
      System.out.println(e.getStackTrace());               
}
%>
<script type="text/javascript">
    var date = '<%=sdf.format(tomorrow) %>'; 

但我同时获得了sdf cannot be resolved例外tomorrow cannot be resolved

我在jsp页面中java.util.*都导入了:java.text.SimpleDateFormat

<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.*" %>
4

1 回答 1

0

你可以使用jstl吗?

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/core-rt" prefix="c-rt" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

<c-rt:set var="now" value="<%=new java.util.Date()%>" />

<script type="text/javascript">
    var date = '<fmt:formatDate value="${now}" type="both" timeStyle="long" dateStyle="long" />'; 
....
于 2012-11-11T19:36:45.510 回答