From: Sandy N. <san...@ho...> - 2002-03-24 16:33:19
|
Hi Jythonistas, Since I've just managed used jython and the orion app server together, thought it might be nice to share the xperience, which was astonishingly smooth. You can download the orion server at http://www.orionserver.com and there's an article about it at http://serverwatch.internet.com/reviews/app-orion.html This howto is inspired and probably borrows heavily from http://jywiki.sourceforge.net/index.php?JythonServlet BTW this is for the windows version. You're on your own with linux, but it then again it should probably be easier (-: Here's what I did: (1) install orion in orion_path (I used version 1.5.4) (2) install jython (unless you have already) in jython_path (jython21) (3) create a folder (let's call it jytest) in orion_path\default-web-app e.g C:\servers\orion\default-web-app\jytest this will contain your jython servlet scripts. (see below for an example which you can copy and paste to jytest) (4) open up jython_path and copy jython_path\jython.jar and jython_path\lib folder to orion_path\default-web-app\WEB-INF\lib e.g. C:\servers\orion\default-web-app\WEB-INF\lib\Lib C:\servers\orion\default-web-app\WEB-INF\lib\jython.jar (5) make an empty folder 'jython' in orion_path\default-web-app\WEB-INF e.g. C:\servers\orion\default-web-app\WEB-INF\jython This will be in your python sys.path, so I guess additional modules, etc.., can be put here. But maybe you have another use. (6) modify web.xml in orion_path\default-web-app\WEB-INF so that it looks something like below (of course making sure that param-value contains the path of the directory in which jython.jar resides) web.xml will probably look something like this: <?xml version="1.0"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> <web-app> <!-- A demo servlet, add servlets below --> <servlet> <servlet-name>snoop</servlet-name> <servlet-class>SnoopServlet</servlet-class> </servlet> <servlet> <servlet-name> pyservlet </servlet-name> <servlet-class> org.python.util.PyServlet </servlet-class> <init-param> <param-name>python.home</param-name> <param-value>C:\servers\orion\default-web-app\WEB-INF\lib</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name> pyservlet </servlet-name> <url-pattern>*.py</url-pattern> </servlet-mapping> </web-app> (7) start orion by type java -jar orion.jar (8) point your browser to http://localhost/jytest/cal.py and you there you are! see that you are now using both both java and jython libs (apologies if this is misformatted) # --- cal.py ----------------------------------------------------------# test jython servlet # java libs import java, javax # python libs import os, calendar html=''' <html> <head> <title>test</title> </head> <body> <p>Today is %(date)s</p> <table align='center' cellpadding=20> <tr> <td>%(cal1)s</td><td>%(cal2)s</td> </tr> </table> <br> Current working directory: %(dir)s <br> <br> files: <font size=-1>%(files)s</font> <br> <br> Information: <hr> %(info)s <br> </body> </html> ''' class cal(javax.servlet.http.HttpServlet): def doGet(self, request, response): response.setContentType("text/html") out = response.getOutputStream() print >> out, html % { 'date': java.util.Date(), 'cal1': make_calendar(2002,2), 'cal2': make_calendar(2002,3), 'dir': os.getcwd(), 'files': os.listdir(os.getcwd()), 'info' : getInfo(request) } out.close() return def make_calendar(year, month): ''' this cool snipplet is due to some other nifty soul other than me... who wrote it originally in python... ''' month_cal = calendar.monthcalendar(year, month) scal = '' scal += "<B>%s.%s</B>" % (month, year) scal += "<TABLE BORDER=1>" for week in month_cal: scal += "\n<TR>" for day in week: scal += "<TD>%s</TD>" % (day or " ") scal += "</TR>" scal += "</TABLE>" return scal def getInfo(request): d = { "JSP Request Method:" : request.getMethod(), "Request URI:": request.getRequestURI(), "Request Protocol:": request.getProtocol(), "Servlet path:" : request.getServletPath(), "Path info": request.getPathInfo(), "Path translated": request.getPathTranslated(), "Query string": request.getQueryString(), "Content length": request.getContentLength(), "Content type": request.getContentType(), "Server name": request.getServerName(), "Server port": request.getServerPort(), "Remote user": request.getRemoteUser(), "Remote address": request.getRemoteAddr(), "Remote host": request.getRemoteHost(), "Authorization scheme": request.getAuthType(), "browser": request.getHeader("User-Agent") } table = '<table align=center border=1>' x = 1 for key in d.keys(): table += '<tr><td bgcolor=%s>%s: %s</td></tr>' % (x and '#CCCCCC' or 'white', key, d[key]) x = not x table += '</table>' return table # --------------------------------------------------------------------- Hope this works for you. (-: best regards, Sandy _________________________________________________________________ Join the worlds largest e-mail service with MSN Hotmail. http://www.hotmail.com |