From: Robert W. B. <rb...@di...> - 2000-12-22 21:30:56
|
Hello all, This was originally on the jython-dev list, but I thought it might be more appropriate here... [Ray] > On Thu, 21 Dec 2000, Ray Leyva wrote: > > Just wondering. Cause we're building a site based solely on Java, and > > JSP. I was wondering if it was possible to use Jython from with JSP, > > and if so can someone send a really really simple ( rudimentary ) > > FooBar, World! style sample. > > > > thx > > rl [Me] > I'm been looking at this as well. So far, I'm unable to use a jythonc > compiled file with Tomcat jsp due to a StackOverflow in __init__ or other > problems loading the inner class. I think I'm missing something though. I've come to a point where I need to ask people what it is I'm missing. The dilemna is the use of jythonc generated classes in JSP pages. For example, I can have a jython class and .jsp page as follows (roughly from Frank Chen's original examples): -------------file: mytest.py--------------------- import java class mytest(java.lang.Object): def __init__(self): self.name = "Jerry" def myget(self): "@sig public String myget()" return self.name def myset(self, name): "@sig public void myset(java.lang.String name)" self.name = name ---------------------------------------------------- This is compiled with "jythonc mytest.py". ------------file: test.jsp------------------- <%@ page import = "mytest" %> <html> <head><title>Jython Test</title></head> <body bgcolor="white"> <% mytest mt = new mytest(); %> My name is <%= mt.myget() %> <% mt.myset("Robert"); %> <br>No, wait, it's <%= mt.myget() %> </font></body></html> ----------------------------------------------- I have never gotten the jythonc compiled file to work, but until today my JSP work was stuck on a win98 machine. Today, I find out that any of my jythonc compiled files work fine on my linux and Solaris boxes. It is as simple as write anything in jython, compile with jythonc and use the <%@ page import = "filename" %> to use it in JSP, with the above example being just the tip of the iceburg. On win98 I still receive a StackOverflow. I have edited the memory properties of the dos .lnk that I use to start tomcat on Windows, and have been through all possible permutations of settings as well as eliminating any backgrounded processes (I think called TSR's on windows?). I still cannot avoid the StackOverflow when Jasper loads the requested jythonc compiled file. All boxes are using Sun jdk1.3, jython-2.0a2, and have 64mb ram. I was hoping that someone who understands windows (not me) could help provide some hints on getting it working. Was editing the .lnk memory properties a likely answer? My memory monitor does not show memory totally full- can I adjust the stack size java uses? Am I looking entirely in the wrong direction by focussing on memory allocation? All classloaders are the same (Jasper/tomcat/sunjdk1.3) so it's not likely jvm/servlet-container. I do not have any additional windows machines to test this on to see if it would be a setup problem on one machine. My sincere thanks in advance for any suggestions. -Robert |
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 |
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 |
From: Robert W. B. <rb...@di...> - 2000-12-24 00:47:58
|
[Finn] > I think that you have jython.jar included on your CLASSPATH before > starting tomcat, correct? Yes. > 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. Excellent! Do you then use TOMCAT_OPTS to set python.home? It seems Jython reads the registry from wherever it finds the jython.jar if I don't set python.home- I'm worried about what happens when a client has 2+ Jython webapps that are self-contained this way. I'll have to try and find out. Also, is it known why the posted example crashes if I use "self.username" as an instance variable instead of the current "self.usrname"? I'll have time next week to find out, just curious if ppl already knew so I could save some time. -Robert |
From: <bc...@wo...> - 2000-12-25 00:37:32
|
[Robert W. Bill] >Also, is it known why the posted example crashes if I use >"self.username" as an instance variable instead of the current >"self.usrname"? I'll have time next week to find out, just curious if ppl >already knew so I could save some time. It is because the getUsername / setUsername methods creates a bean property called "username". Reading or writing to this beanproperty (which is done in the set/get methods) will call the set/get methods again. The good news are that it is easy to work around (as you did) and you'll recognize it immediately the next time it happen. regards, finn |