Just wanted to post my recent experiences installing Jython on my Mandrake 8.2 server so I could run servlets written in Jython. I found that I could not import the standard java modules other than sys in my servlets. The error I kept encountering was "ImportError: Could not import module java" or something to that effect. Interestingly, when I ran Jython on the console, import java went without a hitch. I think I know what happened now, because I got it fixed finally (after 2 days). My script (in file hello2.py) is as follows:
I followed essentially the guide provided here: Jywiki I downloaded the jython-21.class file from sourceforge and then ran the following:
Possible Problem 1 : I installed the jython files into the /home/Jython-2.1 directory. This made it inaccessible to tomcat; maybe it was the directory name or maybe it was outside of the search tree. Possible Problem 2 : The classpath to the java libraries may have been undefined. Solution : In any case, the problems listed above were solved when I installed it into /usr/local/jython as follows:
Then I changed the appropriate entry in web.xml for python.home to point to /usr/local/jython This fixed everything and now tomcat is happy to serve the hello1.py file as a servlet. I read thru some of the mailing lists and I see some people having the same problem. I followed the fixes recommended in those mailing lists but it didn't help me. So I had to come out with my own solution. Hope this helps anyone who has encountered a similar problem with Jython. Jython is really nice to use.
Joined: Aug 03, 2002
Thanks Willson, it's good to find someone like you who gives such information without being asked to.
Thanks for the encouragement. I have learnt a lot from the documented difficulties of others and now that I have a solution, it is only fair I contribute my share. New discovery over the weekend: I can do page forwarding from a Jython servlet. Been reading Jython Essentials and Jython for Java Programmers which are very informative, but have not been able to find documentation on how to do this (needed for a Controller in the MVC paradigm). It seems that all the methods available to a normal Java Servlet is also available to a Jython Servlet. The following snippet worked for me: