Class PyServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.python.util.PyServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class PyServlet extends javax.servlet.http.HttpServlet
This servlet is used to re-serve Jython servlets. It stores bytecode for Jython servlets and re-uses it if the underlying .py file has not changed.

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>
 
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    void
    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)
     

    Methods inherited from class javax.servlet.GenericServlet

    getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • PyServlet

      public PyServlet()
  • Method Details

    • init

      public void init()
      Overrides:
      init in class javax.servlet.GenericServlet
    • service

      public void service(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res) throws javax.servlet.ServletException, IOException
      Specified by:
      service in interface javax.servlet.Servlet
      Overrides:
      service in class javax.servlet.http.HttpServlet
      Throws:
      javax.servlet.ServletException
      IOException
    • destroy

      public void destroy()
      Specified by:
      destroy in interface javax.servlet.Servlet
      Overrides:
      destroy in class javax.servlet.GenericServlet
    • reset

      public void reset()
      Clears the cache of loaded servlets and makes a new PythonInterpreter to service further requests.