From: Updike, C. <Cla...@jh...> - 2004-03-02 18:01:51
|
If you check the javadoc for GenericServlet, <http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/GenericServlet. html#init(javax.servlet.ServletConfig)> you should either override the parameterless version of init: change def init(self,cnfg): to def init(self): or call the superclass version of init, viz: def init(self, cnfg): http.HttpServlet.init(self, cnfg) Either should fix it. -Clark -----Original Message----- From: sh...@ro... [mailto:sh...@ro...] Sent: Tuesday, March 02, 2004 12:26 PM To: jyt...@li... Subject: [Jython-users] having problem with pyservlet When I try to run the following: from javax.servlet import http from com.ziclix.python.sql import zxJDBC class ValidateLogon(http.HttpServlet): def init(self,cnfg): url = "jdbc:mysql://localhost/testdb" usr = "" passwd = "" driver = "com.mysql.jdbc.Driver" self.db = zxJDBC.connect(url,usr,passwd,driver) self.c = self.db.cursor() def doPost(self,req,res): usrname = req.getParameter("username") usrpasswd = req.getParameter("password") #res.setContentType("text/html") out = res.getWriter() self.c.execute("select * from users where userid = ? and pswd = ?", (usrname, usrpasswd)) if (self.c.fetchall()) != None: rd = self.getServletContext().getRequestDispatcher("homepage.jsp") rd.forward(self,req,res) else: res.sendRedirect("invalidlogin.html") def destroy(self): self.c.close() self.db.close() I get the following error message: java.lang.NullPointerException javax.servlet.GenericServlet.getServletContext(GenericServlet.java:204) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 ) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:25) java.lang.reflect.Method.invoke(Method.java:324) org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java) org.python.core.PyMethod.__call__(PyMethod.java) org.python.core.PyObject.__call__(PyObject.java) org.python.core.PyInstance.invoke(PyInstance.java) org.python.pycode._pyx1.doPost$3(E:\Tomcat 5.0\webapps\jython\ValidateLogon.py:20) org.python.pycode._pyx1.call_function(E:\Tomcat 5.0\webapps\jython\ValidateLogon.py) org.python.core.PyTableCode.call(PyTableCode.java) org.python.core.PyTableCode.call(PyTableCode.java) org.python.core.PyTableCode.call(PyTableCode.java) org.python.core.PyFunction.__call__(PyFunction.java) org.python.core.PyMethod.__call__(PyMethod.java) org.python.core.PyObject.__call__(PyObject.java) org.python.core.PyObject._jcallexc(PyObject.java) org.python.proxies.main$ValidateLogon$1.doPost(Unknown Source) javax.servlet.http.HttpServlet.service(HttpServlet.java:763) org.python.proxies.main$ValidateLogon$1.service(Unknown Source) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) org.python.util.PyServlet.service(PyServlet.java) Im running this in Tomcat 5 and can run other jython servlets successfully. Any pointers on what Im doing wrong will be highly appreciated. 1 ------------------------------------------------------- SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now! http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click _______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users |