java.lang.IllegalArgumentException: Cannot format given Object as a Date

【异常报错提示】:

org.apache.jasper.JasperException:CannotformatgivenObjectasaDate

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)

rootcause

java.lang.IllegalArgumentException:CannotformatgivenObjectasaDate

java.text.DateFormat.format(UnknownSource)

java.text.Format.format(UnknownSource)

com.lyang.governmentbill.CCI.jsp.Bean.ReportManagerBean.reportManagerBean(ReportManagerBean.java:115)

org.apache.jsp.reportList_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)

noteThefullstacktraceoftherootcauseisavailableintheApacheTomcat/5.5.17logs.

【异常处理】

ApacheTomcat/5.5.17

ReportManagerBean.java:115行代码如下:

Stringbegin=sdf.format(begintime);

注:sdf为:SimpleDateFormatsdf=newSimpleDateFormat("yyyy年MM月dd日");

begintime为:Stringbegintime=request.getParameter("begintime");

传值是对象不是日期类型将begintime转化一下

将Stringbegin=sdf.format(begintime);改为:Stringbegin=sdf.format(DateFormat.getDateInstance().parse(begintime));就好了。SimpleDateFormat的format方法是:publicfinaljava.lang.Stringformat(java.util,Dateorg0);format方法应该传一个Date类型的参数,而不是String或者是其它的。

相关推荐