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 | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private Map | |
| private static final Pattern | |
| protected static final String | |
| private PythonInterpreter | |
| protected static final Logger | |
| public static final String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected static <T> T | |
| protected static PythonInterpreter | |
| public void | destroy()
Overrides javax. Implements javax. Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. |
| private void | |
| protected static String | |
| private synchronized HttpServlet | |
| public void | init()
Overrides javax. A convenience method which can be overridden so that there's no need
to call |
| protected static void | init(Properties props, ServletContext context)
PyServlet's initialization can be performed as a ServletContextListener or as a regular servlet, and this is the shared init code. |
| private HttpServlet | |
| public void | reset()
Clears the cache of loaded servlets and makes a new PythonInterpreter to service further requests. |
| public void | service(ServletRequest
the req, ServletResponse HttpServletRequest object that
contains the request the client made of
the servletthe res)HttpServletResponse object that
contains the response the servlet returns
to the clientOverrides javax. Implements javax. Dispatches client requests to the protected
|
| cache | back to summary |
|---|---|
| private Map<String, PyServlet. | |
| FIND_NAME | back to summary |
|---|---|
| private static final Pattern FIND_NAME | |
| INIT_ATTR | back to summary |
|---|---|
| protected static final String INIT_ATTR | |
| interp | back to summary |
|---|---|
| private PythonInterpreter interp | |
| logger | back to summary |
|---|---|
| protected static final Logger logger | |
| SKIP_INIT_NAME | back to summary |
|---|---|
| public static final String SKIP_INIT_NAME | |
| PyServlet | back to summary |
|---|---|
| public PyServlet() | |
| createInstance | back to summary |
|---|---|
| protected static <T> T createInstance(PythonInterpreter interp, File file, Class<T> type) throws ServletException | |
| createInterpreter | back to summary |
|---|---|
| protected static PythonInterpreter createInterpreter(ServletContext servletContext) | |
| destroy | back to summary |
|---|---|
| public void destroy() Overrides javax. Implements javax. Doc from javax. Called by the servlet container to indicate to a servlet that the
servlet is being taken out of service. See
| |
| destroyCache | back to summary |
|---|---|
| private void destroyCache() | |
| getRootPath | back to summary |
|---|---|
| protected static String getRootPath(ServletContext context) | |
| getServlet | back to summary |
|---|---|
| private synchronized HttpServlet getServlet(String path) throws ServletException, IOException | |
| init | back to summary |
|---|---|
| public void init() Overrides javax. Doc from javax. A convenience method which can be overridden so that there's no need
to call Instead of overriding
| |
| init | back to summary |
|---|---|
| protected static void init(Properties props, ServletContext context) PyServlet's initialization can be performed as a ServletContextListener or as a regular servlet, and this is the shared init code. If both initializations are used in a single context, the system state initialization code only runs once. | |
| loadServlet | back to summary |
|---|---|
| private HttpServlet loadServlet(String path) throws ServletException, IOException | |
| reset | back to summary |
|---|---|
| public void reset() Clears the cache of loaded servlets and makes a new PythonInterpreter to service further requests. | |
| service | back to summary |
|---|---|
| public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException Overrides javax. Implements javax. Doc from javax. Dispatches client requests to the protected
| |
| Modifier and Type | Field and Description |
|---|---|
| public long | |
| public HttpServlet |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| CacheEntry | back to summary |
|---|---|
| pack-priv CacheEntry(HttpServlet servlet, long date) | |