Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## example.servlet.basic
Class InitServlet

    example.servlet.basic.InitServlet

public class 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.

- /servlet/servlet-a will use servlet-a defined above. init-a will be 'value-a'.
- /servlet/servlet-b will use servlet-b defined above. init-a will be 'value-b'.
- /servlet/example.servlet.basic.InitServlet will use an unnamed servlet. init-a will be null.

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(example.servlet.basic.HttpServletRequest request, example.servlet.basic.HttpServletResponse response)` Handles GET requests.
`void` | `init()` The `init()` method is called when the servlet is initialized.

Constructor Detail

### InitServlet

    public InitServlet()

Method Detail

### init

    public void init()
              throws example.servlet.basic.ServletException

  The `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.

### doGet

    public void doGet(example.servlet.basic.HttpServletRequest request,
                      example.servlet.basic.HttpServletResponse response)
               throws java.io.IOException,
                      example.servlet.basic.ServletException

  Handles GET requests. Resin will call the doGet method when the browser sends a GET request.
  Parameters:
    `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.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD