我有以下代碼:解析功能不能正常工作
String date_p = request.getParameter("myText");
DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
java.util.Date frmDate = sdf.parse(date_p);
我得到的錯誤是:
type Exception report
message An exception occurred processing JSP page /demo3.jsp at line 22
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /demo3.jsp at line 22
19:
20: String date_p = request.getParameter("myText");
21: DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
22: java.util.Date frmDate = sdf.parse(date_p);
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:575)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NullPointerException
java.text.SimpleDateFormat.parse(Unknown Source)
java.text.DateFormat.parse(Unknown Source)
org.apache.jsp.demo3_jsp._jspService(demo3_jsp.java:106)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
爲什麼不工作的解析函數? 我已經導入這些包,以及 -
是你的問題是一個NPE,閱讀你的棧跟蹤 –
@NicolasFilotto它的一個JSP頁面。 date_p值取自用戶。我不能在這裏理解的問題 – StevieG