From: Brian Z. <bri...@ya...> - 2001-01-31 17:34:39
|
Hello list, Following http://groups.yahoo.com/group/jpython/message/3714 I succeeded making servlet running under PyServlet wrapper/handler on win2k tomcat3.2.1. So far so good, I can run simple script like: import sys, java, javax class hello(javax.servlet.http.HttpServlet): def doGet(self, req, res): res.setContentType("text/html"); out = res.getOutputStream() out.println("""\ <html> <head><title>Hello World</title></head> <body>Hello World! <P> current server time is: %s </P> </body> </html> """ % (java.util.Date())) out.close() return Or even dynamicly generate PNG graph thanks to the new javax.imagio package from Sun. I don't expect any difficulty hooking up with database using JDBC. However, when trying to port SnoopServlet from java to jython, I found that PyServlet really doesn't handover any instant variables to the jython HttpServlet subclass except (request, response). So enum = self.getInitParameterNames() will got a NullPointerException. Any operation involve self.attribute like self.getServletContext() will also fail. I don't think jythonc compiled classes will have this problem because the jython servlet handle service() directly bypassing PyServlet. So my questions are: 1. Am I missing anything? Any misunderstanding of the API? 2. Any way around? Anyone got a better PyServlet? 3. If I'm the first one got bitten, any idea how we may overcome this problem? Seeing the power of dynamic python scripting at work (instant feedback without re-compiling), I really appreciate what have been done so far, and want to get it going. Here are some of my ideas: 1. We can have two seperate subclasses of HttpServlet in java: one possibly named ServletPyHandler, doing what PyServlet currently is doing, dispatching service() calls to jython servlet; the other JyServlet being superclass of all jython servlets, with constructor JyServlet(ServletPyHandler), so JyServlet always has a ref to the ServletPyHandler instance; The downside of this approach is that now jythonc compiled servlet and dynamically interpreted servlet have to be written differently. 2. Have ServletPyHandler do somthing to the jython servlet class right before dispatching service() call, so that inside jython servlet, later when messages like self.getInitParameterNames() will be redirected back to ServletPyHandler. TIA for any ideas, /Brian |