java - servlet throws a NPE cant figur out why -
public class addmovieservlet extends httpservlet { private static final long serialversionuid = 1l; /** * @see httpservlet#httpservlet() */ public addmovieservlet() { super(); // todo auto-generated constructor stub } @override protected void dopost(httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception { super.dopost(req, resp); process(req,resp); } @override protected void doget(httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception { // todo auto-generated method stub super.doget(req, resp); process(req,resp); } //my process method protected void process(httpservletrequest req , httpservletresponse resp) { //we set requests of elements of our movie string name = req.getparameter("name"); long date = long.parselong(req.getparameter("reldate").tostring()); string lang = req.getparameter("lang"); int rating = integer.parseint(req.getparameter("rating")); string descr = req.getparameter("descr"); string dburl = "jdbc:mysql://localhost:8080/moviedb"; string query = "insert movietable values (?,?,?,?,?)"; connection myconnection = null; preparedstatement mystatement = null; try { class.forname("com.mysql.jdbc.driver"); myconnection = drivermanager.getconnection(dburl,"root","root"); mystatement = myconnection.preparestatement(query); mystatement.setstring(1, name); mystatement.setlong(2, (int)date); mystatement.setstring(3, lang); mystatement.setint(4, rating); mystatement.setstring(5, descr); int insertedornot = mystatement.executeupdate(); system.out.println("inserted " + insertedornot); } catch (classnotfoundexception | sqlexception e) { // todo auto-generated catch block e.printstacktrace(); }finally { try { if(myconnection!=null) myconnection.close(); } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
}
severe: servlet.service() servlet addmovieservlet threw exception java.lang.nullpointerexception @ wimc.serv.addmovieservlet.process(addmovieservlet.java:52) @ wimc.serv.addmovieservlet.doget(addmovieservlet.java:42) @ javax.servlet.http.httpservlet.service(httpservlet.java:617) @ javax.servlet.http.httpservlet.service(httpservlet.java:717) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:290) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:233) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:191) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:127) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:102) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:298) @ org.apache.coyote.http11.http11processor.process(http11processor.java:857) @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:588) @ org.apache.tomcat.util.net.jioendpoint$worker.run(jioendpoint.java:489) @ java.lang.thread.run(unknown source)
req.getparameter("reldate")
returns null.
Comments
Post a Comment