public class PyServlet
extends javax.servlet.http.HttpServlet
e.g. http://localhost:8080/test/hello.py
from javax.servlet.http import HttpServlet
class hello(HttpServlet):
def doGet(self, req, res):
res.setContentType("text/html");
out = res.getOutputStream()
print >>out, "<html>"
print >>out, "<head><title>Hello World, How are we?</title></head>"
print >>out, "<body>Hello World, how are we?"
print >>out, "</body>"
print >>out, "</html>"
out.close()
in web.xml for the PyServlet context:
<web-app>
<servlet>
<servlet-name>PyServlet</servlet-name>
<servlet-class>org.python.util.PyServlet</servlet-class>
<init-param>
<param-name>python.home</param-name>
<param-value>/usr/home/jython-2.5</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>PyServlet</servlet-name>
<url-pattern>*.py</url-pattern>
</servlet-mapping>
</web-app>
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
SKIP_INIT_NAME |
| Constructor and Description |
|---|
PyServlet() |
| Modifier and Type | Method and Description |
|---|---|
void |
destroy() |
void |
init() |
void |
reset()
Clears the cache of loaded servlets and makes a new PythonInterpreter to service further
requests.
|
void |
service(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res) |
public static final java.lang.String SKIP_INIT_NAME
public void init()
init in class javax.servlet.GenericServletpublic void service(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res)
throws javax.servlet.ServletException,
java.io.IOException
service in interface javax.servlet.Servletservice in class javax.servlet.http.HttpServletjavax.servlet.ServletExceptionjava.io.IOExceptionpublic void destroy()
destroy in interface javax.servlet.Servletdestroy in class javax.servlet.GenericServletpublic void reset()