java - JSP error at line 31 -
when running jsp page drops me error , suggestion in order fix , (i know jsp java not good)...
type exception report
message exception occurred processing jsp page /assets/jsp/create-dest-code.jsp @ line 31
description server encountered internal error prevented fulfilling request.
exception org.apache.jasper.jasperexception: exception occurred processing jsp page /assets/jsp/create-dest-code.jsp @ line 31
28: if(id > -1) 29: { 30: int insert_ch; 31: for(int i=0;i insert_ch=mystatement.executeupdate("insert dest_has_categories (dest_iddest,categories_idcategories) values ('"+id+"','"+cat[i]+"')"); 34: }
stacktrace: org.apache.jasper.servlet.jspservletwrapper.handlejspexception(jspservletwrapper.java:574) org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:476) org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:396) org.apache.jasper.servlet.jspservlet.service(jspservlet.java:340) javax.servlet.http.httpservlet.service(httpservlet.java:729) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52)
root cause java.lang.nullpointerexception org.apache.jsp.assets.jsp.create_002ddest_002dcode_jsp._jspservice(create_002ddest_002dcode_jsp.java:136) org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) javax.servlet.http.httpservlet.service(httpservlet.java:729) org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:438) org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:396) org.apache.jasper.servlet.jspservlet.service(jspservlet.java:340) javax.servlet.http.httpservlet.service(httpservlet.java:729) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52)
note full stack trace of root cause available in apache tomcat/8.0.33 logs.
my code :
<% string id8=request.getparameter("id8"); //country field string id9=request.getparameter("id9"); //city field string id10=request.getparameter("id10"); //url field int id = -1; class.forname("com.mysql.jdbc.driver"); string mydatabase = "jdbc:mysql://localhost:3306/project_app?user=root&password=1234"; connection myconnection = drivermanager.getconnection(mydatabase); statement mystatement = myconnection.createstatement(); string sqlinsert = "insert dest(country,city,url) values ('"+id8+"', '"+id9+"','"+id10+"')"; mystatement.executeupdate(sqlinsert); resultset rs = mystatement.executequery("select iddest dest country='"+id8+"' , city='"+id9+"' , url='"+id10+"'" ); while (rs.next()) { id=rs.getint(1); } string cat[]=request.getparametervalues("dest1"); if(id > -1) { int insert_ch; for(int i=0;i<cat.length;i++) { insert_ch=mystatement.executeupdate("insert dest_has_categories (dest_iddest,categories_idcategories) values ('"+id+"','"+cat[i]+"')"); } } mystatement.close(); myconnection.close(); %> <h1 style="color:blue;">successful registration </h1>
i assume once know line #31, able fix npe many other questions of type let's focus on how find line #31 in case.
according stacktrace using tomcat 8
, source code of jsp file /assets/jsp/create-dest-code.jsp
in $tomcat_home/work/catalina/localhost/assets/org/apache/jsp/jsp/create-dest-code_jsp.java
, here check line #31 , know how fix it.
actually have answer here:
28: if(id > -1) 29: { 30: int insert_ch; 31: for(int i=0;i insert_ch=mystatement.executeupdate("insert dest_has_categories (dest_iddest,categories_idcategories) values ('"+id+"','"+cat[i]+"')"); 34: }
it seems variable cat
null
means have no value parameter dest1
.