|
From: <bc...@wo...> - 2000-12-23 23:29:03
|
[Robert W. Bill]
>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.
Good to hear that it worked out.
>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.
I think that you have jython.jar included on your CLASSPATH before
starting tomcat, correct?
With tomcat 4.0m5 (the only one I have tested with) I had success with
copying jython.jar to %TOMCAT_HOME%\webapps\jython\WEB-INF\lib. This way
the deployment .war can be completely self contained.
regards,
finn
|