of Jython

Jython = Java + Python
Servlet = server applet (maybe :lol:)

Servlet in less than a day
[src]

1. Install Java (J2SE/JSE)

2. Install Tomcat (ver 5.0xx)

3. Install jython (ver 2.2)

4. Create these structure (italics = new folder):
- tomcat\webapps\jythondemo
- tomcat\webapps\jythondemo\WEB-INF
- tomcat\webapps\jythondemo\WEB-INF\lib
- tomcat\webapps\jythondemo\WEB-INF\classes

5. Inside jython directory (i.e c:\program files\jython) there's a file named jython.jar, copy that into tomcat\common\lib

6. create a web.xml file in tomcat\webapps\jythondemo\WEB-INF with the following content

<web-app>
<servlet>
<servlet-name>PyServlet</servlet-name>
<servlet-class>org.python.util.PyServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>PyServlet</servlet-name>
<url-pattern>*.py</url-pattern>
</servlet-mapping>
</web-app>


7. Create JythonServlet1.py inside tomcat\webapps\jythondemo with the following content:


from javax.servlet.http import HttpServlet

class JythonServlet1 (HttpServlet):
def doGet(self,request,response):
self.doPost (request,response)

def doPost(self,request,response):
toClient = response.getWriter()
response.setContentType ("text/html")
toClient.println ("<html><head><title>Servlet Test</title>" + "<body><h1>Servlet Test</h1></body></html>")

8. Start your Tomcat server

9. go to http://localhost:8080/jythondemo/JythonServlet1

FIN

p/s: since it is a matter of drag & drop (somewhat), this can be easily deployed inside a hosting, provided that they support java that is..

1 comment:

:: unexistance :: said...

follow on:
http://www.hotales.org/writings/jython-servlet-jsp.html