writing servlets with JPython

Robert W. Bill rbill at digisprings.com
Tue Aug 1 22:27:49 EDT 2000


On Tue, 1 Aug 2000 borisg at captura.com wrote:
> I am trying to write a servlet in JPython. My very simple test
> looks like this:
> 
> from javax.servlet import *
> from javax.servlet.http import *
> from java.io import *
> 
> class HelloWorldServlet(HttpServlet):
>     def service(req, res):
>         res.setContentType("text/html")
>         out = res.getWriter()
>         out.println("<html><head><title>Hello World!</title></head>")
>         out.println("<body><h1>Hello World!</h1></body></html>")
> 
> This compiles (with jpythonc) and deploys just fine, but when I
> try to call it I get an exception: "HelloWorldServlet does not
> implement javax.servlet.Servlet". Java version of the class,
> which extends HttpServlet, works.
> 
> Any ideas?
> 
> boris

Although I've been away from JPython for some time, I have
some ideas:

1. The method service should have a 'self' argument, as in- 
	def service(self, req, res):  
--most likely just an email typo, so more ideas below...

2. At the time I used JPython, it did not work to do 'from
whatever import *'.  It was the import * that it didn't like.
try:
	from javax.servlet.http import HttpServlet
			- or -
	from javax.servlet import http
	(then you just have to add explicit package names)

3. A common suggestion is to get the Finn Bock errata.
found at:
http://sourceforge.net/project/filelist.php?group_id=1842 

4. Looking through the newsgroup archives for servlet info is 
also a good idea, there is informative posts on servlets.
archives at: http://www.python.org/pipermail/jpython-interest/

5. If all else fails, repost to the jpython-interest list -
The folks there will no doubt make my ramblings obsolete :)

-robert




More information about the Python-list mailing list