A servlet is any Java class with a null-arg constructor that
implements the Servlet API.
Simple servlets should extend HttpServlet to create servlets.
Servlets that need full control should extend GenericServlet.
Location
Servlets are usually loaded from WEB-INF/classes under the application's
root. To add a servlet test.MyServlet, create the java file:
/www/myweb/WEB-APP/classes/test/MyServlet.java
Servlets can also live in the global classpath.
Configuration
Servlet configuration for Resin is in the resin.conf file.
<servlet servlet-name='hello'
servlet-class='test.HelloServlet'
load-on-startup>
<init-param param1='value1'/>
<init-param param2='value2'/>
</servlet>
Dispatch
The servlet engine selects servlets based on the
servlet-mapping configuration. Servlets can use the
special 'invoker' servlet or they can be configured to execute directly.
To get a path info, your servlet needs to use a wildcard. In the
following example, /Hello will match the 'hello' servlet, but
/Hello/there will match the 'defaultServlet' servlet with a pathinfo
of /Hello/there.
<servlet-mapping url-pattern='/'
servlet-name='defaultServlet'/>
<servlet-mapping url-pattern='/Hello'
servlet-name='hello'/>
<servlet-mapping url-pattern='/servlet/*'
servlet-name='invoker'/>
<servlet-mapping url-pattern='*.jsp'
servlet-name='com.caucho.jsp.JspServlet'/>
Life cycle
Servlets are normally initialized when they are first loaded. You can
force loading on startup using the 'load-on-startup' attribute to the
servlet configuration. This is a useful technique for the equivalent
of the global.jsa file.
A servlet can count on having only one instance per
application (JVM) unless it implements SingleThreadedModel.
Servlet requests are handed by the service routine.
Since the servlet engine is multithreaded, multiple threads may call
service simultaneously.
When the application closes, the servlet engine will call
destroy . Note, applications always close and are restarted
whenever a servlet changes. So init and destroy
may be called many times while the server is still up.
|