有时插入错误进入数据库

时间:2017-08-24 16:19:55

标签: java nullpointerexception

我有一个网站,当用户提交表单时,我在.jsp文件中使用了表单,操作转到servlet,在数据库中插入数据。有时它工作正常没有任何问题,有时甚至用户提交表格没有插入数据库。

任何人都可以建议我,问题是什么。

    24-Aug-2017 01:58:43.958 SEVERE [http-nio-13214-exec-3] 
    org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for 
    servlet [NewServlet] in context with path [] threw exception
    java.lang.NullPointerException
    at org.example.test.NewServlet.processRequest(NewServlet.java:154)
    at org.example.test.NewServlet.doGet(NewServlet.java:389) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFil
   terChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

    24-Aug-2017 01:58:50.928 SEVERE [http-nio-13214-exec-9] 
    org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for 
    servlet [NewServlet] in context with path [] threw exception
    java.lang.NullPointerException
    at org.example.test.NewServlet.processRequest(NewServlet.java:154)
    at org.example.test.NewServlet.doGet(NewServlet.java:389)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

的index.jsp

<form action="NewServlet" method="post" onsubmit="myFunction();">
<table>
<tbody>
<tr>
<td><sql:query dataSource="${snapshot}" var="subjects1">
SELECT * FROM glf2 ORDER BY RAND()LIMIT 1
</sql:query>
<c:set var="comments_m1" value="${subjects1.rows[0]}"/>
${comments_m1.comment_message} 
</td>
</tr>
<tr>
<td><sql:query dataSource="${snapshot}" var="subjects2">
SELECT * FROM egy ORDER BY RAND()LIMIT 1
</sql:query>
<c:set var="comments_m2" value="${subjects2.rows[0]}"/>
${comments_m2.comment_message} 
</td>
</tr>
</tbody>
</table>
<input type="hidden" name="com" value="${comments_m1.comment_message}"/>
<input type="hidden" name="com" value="${comments_m2.comment_message}"/>
<button onclick="submit">submit</button>  
</form> 
<script>
function myFunction()
{ check all filleds are selected}
</script>

从数据库中选择并在屏幕上显示的评论消息 并且用户需要选择一些选项,然后将注释消息和用户选项插入到数据库表中。

newservlet.java根据日志文件中的getParametersValues

中的问题
try (PrintWriter out = resp.getWriter()) {
comment1= req.getParameterValues("com");
for(int z=0; z<comment1.length;z++)
comment[z] = new String(comment1[z].getBytes("ISO-8859-1"),"UTF-8");

0 个答案:

没有答案