|
From: Robert W. B. <rb...@di...> - 2000-12-23 22:02:42
|
Hello all,
I've had progress with JSP and Jython and thought I would post
some info for those that expressed interest.
My previous posts noted difficulty in using jythonc compiled files with
JSP on Windows. However, the machine I was using had multiple JDK's
installed. Because of my troubles, I uninstalled all jdks and
re-installed only sun's 1.2.2 (out of convenience- I had the installer on
the desktop), and all of the JSP problems that I was having are
gone. It's odd that other Java apps were working fine, and I was sure
tomcat and jython/jythonc both pointed to the same jdk, but nonetheless
this was a solution for me.
A simple example of using Jythonc classes with tomcat is (using Tomcat
3.2, jdk1.2.2_07, Win98):
1. Make a context ("jython" in this example).
2. compile following jython file with
"jythonc NameHandler.py"
(NOTE: changing the instance variable "usrname" to "username" is
catastrophic- very interesting ;)
--------------jython file: NameHandler.py----------------
import java
class NameHandler(java.lang.Object):
def __init__(self):
self.usrname = "Fred"
def getUsername(self):
"@sig public String getname()"
return self.usrname
def setUsername(self, name):
"@sig public void setname(java.lang.String name)"
self.usrname = name
----------------------------------------------------------
3. Copy NameHandler.class & NameHandler$_PyInner.class to
\%TOMCAT_HOME%\webapps\jython\WEB-INF\classes
4. Make test.jsp file from below
--------------jsp file: test.jsp--------------------------
<%@ page import = "mytest" %>
<html>
<head><title>hello</title></head>
<body bgcolor="white">
Hello, my name is
<% NameHandler nh = new NameHandler(); %>
<%= nh.getUsername() %> <br>
No! wait...
<% nh.setUsername("Robert"); %>
, It's really <%= nh.getUsername() %>.
</font>
</body>
</html>
-----------------------------------------------------------
5. Place test.jsp file in
context (ie- "\%TOMCAT_HOME\webapps\jython\jsp\test.jsp")
Restart Tomcat and visit
"http://localhost:8080/jython/jsp/test.jsp". This
is it.
Using jythonc compiled files, importing org.python.util.PythonInterpreter
directly in the jsp, and writing java classes/beans that import
PythonInterpreter have now all worked well for me with JSP.
My next step is a snappy jython memento for persistence- maybe even
setting python.security.respectJavaAccessibility = false
to see what things can be done then. All hints welcome.
-Robert
|