tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Zhou" <>
Subject Fw: [Jython-users] servlet problem self.getInitParameterNames() under PyServlet wrapper
Date Wed, 31 Jan 2001 18:40:05 GMT
Hope I can get some insight and suggestion from tomcat developers (like
which is the best class to subclass as jython servlet handler; what are the
needed instance variables to be passed to jython servlet, etc.). The
PyServlet code is available at .

I believe servlet in jython under tomcat has huge, huge potentials. IMHO
JythonServlet vs. JSP is almost like mod_perl vs. mod_php, only that
everything's in Java.

Appreciate any help,


----- Original Message -----
From: "Brian Zhou" <>
To: <>
Cc: <>
Sent: Wednesday, January 31, 2001 9:34 AM
Subject: [Jython-users] servlet problem self.getInitParameterNames() under
PyServlet wrapper

Hello list,

Following 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):
      out = res.getOutputStream()
<head><title>Hello World</title></head>
<body>Hello World!
current server time is: %s
""" % (java.util.Date()))

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

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

TIA for any ideas,


> _______________________________________________
> Jython-users mailing list

View raw message