From: <bc...@wo...> - 2001-02-07 14:05:51
|
[Robert W. Bill] >In using Tomcat-3.2.1, Jython-2.0, sun jdk-1.2.2, win98. My tests have been with tomcat-4.0m5, jdk1.3 & WinNT. >I've >placed jython.jar in %TOMCAT_HOME%\webapps\jython\WEB-INF\lib and >would also like to place the below servlet (and many frozen >modules) in the same lib directory as jyDispatch.jar. I copied the jyDispatch.jar to ...\WEB-INF\lib. The web.xml contained: <web-app> <servlet> <servlet-name>jyDispatch</servlet-name> <servlet-class>jyDispatch</servlet-class> </servlet> <servlet-mapping> <servlet-name>jyDispatch</servlet-name> <url-pattern>*.py</url-pattern> </servlet-mapping> </web-app> >Ahhh, the >dream of an entirely frozen webapp that could be delivered to >clients in a *.war file just like all the java servlet/JSP >webapps out there, but secretly using Jython :) Difficult as long as the dispatcher is written in jython. In the recent PyServlet.java, the dispatcher can initialize the PythonInterpreter with a usefull python.home because it is written in java. So the dream is possible with the newly added PyServlet.java code. The application is not frozen and the use of jython is quite visible if the user looks in the WEB-INF directory, but with a web.xml file likes this: <web-app> <!-- The JSP page compiler and execution servlet --> <servlet> <servlet-name>PyServlet</servlet-name> <servlet-class>org.python.util.PyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>PyServlet</servlet-name> <url-pattern>*.py</url-pattern> </servlet-mapping> </web-app> inside a .war file like this: test.py WEB-INF/web.xml WEB-INF/lib/jython.jar WEB-INF/lib/Lib/javaos.py the application is deployable without any outside code or configuration (only when using the CVS version of Jython). >Here's the code: >-------------------------------------------------------------- >#filename: jyDispatch.py >import sys >sys.prefix="." >from javax import servlet >from javax.servlet import http >import os > >class jyDispatch(http.HttpServlet): > def service(self,req, res): > 'Jython servlet dispatcher' > mtimes = {} > ctx = self.getServletContext() > > #test junk > out = res.getWriter() > out.println("<br>sys.path=" + str(sys.path)) > out.println("<br>sys.prefix=" + str(sys.prefix)) > out.println("<br>cwd=" + str(sys.getcwd())) I think you meant os.getcwd(). > # Get the path of the *.py file to be dispatched > path = ctx.getRealPath( req.getServletPath() ) > mtime = os.stat(path)[7] This works for my using the CVS and the setup I described at the very top. > #Other stuff... >---------------------------------------------------------------- > >The "sys.prefix='.'" was added as suggested and This hack is no longer needed with the CVS version. regards, finn |