将⽇期格式化成YYYY年M⽉的格式HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Cannot format given Object as a Date
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.IllegalArgumentException: Cannot format given Object as a Date
vernmentbill.CCI.jsp.portManagerBean(ReportManagerBean.java:115)
org.portList_jsp._jspService(reportList_jsp.java:141)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
--------------------------------------------------------------------------------
代码如下:
try {
while (rs.next()) {
row = ateRow(i + 1);
i++;
for (int j = 1; j <= columns.length; j++) {
cell = ateCell((short) (j-1));
cell.setEncoding((short) 1);
boolean dataFlag=false;
for(int k = 0;k<dealColumns.length;k++){
if(dealColumns[k].equals(String.valueOf(j-1))){
dataFlag=true;
style1.setDataFormat((short)4);
}
}
if(dataFlag){
cell.Double(j));
cell.setCellStyle(style1);
}else{
if(j==7){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年M⽉");
String strDate =sdf.DateInstance().String(7)));
cell.setCellValue(strDate);
}else{
cell.String(j));
String String(7);
cell.setCellStyle(style);
}
}
}
}
} catch (SQLException e1) {
e1.printStackTrace();
}
} catch (SQLException e) {
e.printStackTrace();
}
finally{
try {
rs.close();
stat.close();
java时间日期格式转换
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
原因:SimpleDateFormat 的format⽅法是:public final java.lang.String format(java.util,Date org0); format⽅法应该传⼀个Date 类型的参数,⽽不是String 或者是其它的。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论