解析函数不起作用

时间:2016-06-14 15:29:24

标签: java mysql sql oracle jsp

我有以下代码:

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)

为什么解析功能不起作用? 我也导入了这些包 - “java.sql。,java.util。,java.text。*”

1 个答案:

答案 0 :(得分:2)

您的date_p似乎为空,您需要检查您是否在GET参数或POST参数中传递了属性myText