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 |
---|---|
protected static java.lang.String |
INIT_ATTR |
protected static java.util.logging.Logger |
logger |
static java.lang.String |
SKIP_INIT_NAME |
Constructor and Description |
---|
PyServlet() |
Modifier and Type | Method and Description |
---|---|
protected static <T> T |
createInstance(PythonInterpreter interp,
java.io.File file,
java.lang.Class<T> type) |
protected static PythonInterpreter |
createInterpreter(javax.servlet.ServletContext servletContext) |
void |
destroy() |
protected static java.lang.String |
getRootPath(javax.servlet.ServletContext context) |
void |
init() |
protected static void |
init(java.util.Properties props,
javax.servlet.ServletContext context)
PyServlet's initialization can be performed as a ServletContextListener or as a regular
servlet, and this is the shared init code.
|
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) |
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
protected static final java.util.logging.Logger logger
public static final java.lang.String SKIP_INIT_NAME
protected static final java.lang.String INIT_ATTR
public void init()
init
in class javax.servlet.GenericServlet
protected static void init(java.util.Properties props, javax.servlet.ServletContext context)
protected static PythonInterpreter createInterpreter(javax.servlet.ServletContext servletContext)
protected static java.lang.String getRootPath(javax.servlet.ServletContext context)
public void service(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res) throws javax.servlet.ServletException, java.io.IOException
service
in interface javax.servlet.Servlet
service
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
java.io.IOException
public void destroy()
destroy
in interface javax.servlet.Servlet
destroy
in class javax.servlet.GenericServlet
public void reset()
protected static <T> T createInstance(PythonInterpreter interp, java.io.File file, java.lang.Class<T> type) throws javax.servlet.ServletException
javax.servlet.ServletException