|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--HttpServlet | +--example.servlet.basic.InitServlet
Shows how to get initialization parameters from the configuration file.
The following is a sample configuration for the examples. It uses Resin's short syntax which is more scannable and maintainable.
<web-app> <context-param context-a='context-value-a'/> <servlet servlet-name='servlet-a' servlet-class='example.servlet.basic.InitServlet'> <init-param init-a='value-a'/> </servlet> <servlet servlet-name='servlet-b' servlet-class='example.servlet.basic.InitServlet'> <init-param init-a='value-b'/> </servlet> <servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/> </web-app>
The specific servlet instance depends on the URL. In the above example, there are three URLs that will use the InitServlet, but all three will use different servlet instances.
The example includes a count variable so you can see how the servlet instances are reused. Since Resin only creates a single servlet instance, servlet programmers must be aware of threading issues.
Constructor Summary | |
InitServlet()
|
Method Summary | |
void |
doGet(HttpServletRequest request,
HttpServletResponse response)
Handles GET requests. |
void |
init()
The init() method is called when the servlet is
initialized. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public InitServlet()
Method Detail |
public void init() throws ServletException
init()
method is called when the servlet is
initialized. For most servlets, it will be called on the first
request to the servlet. For load-on-startup servlets, it will be
called when the web-app initializes.
Servlets normally use init() to cache initial lookups. A typical example is caching a lookup of a database DataSource or an EJB home.
ServletException
public void doGet(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException
request
- the request object contains the data from
the browser's request.response
- the response object contains methods to send
data back to the browser.
java.io.IOException
ServletException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |