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 MappingServlet

    example.servlet.basic.MappingServlet

public class MappingServlet

Shows how the servlet-mapping in the resin.conf and web.xml works.

The following is a sample configuration for the examples. It uses Resin's short syntax which is more scannable and maintainable.

     <web-app>

     <servlet servlet-name='map-a'
              servlet-class='example.servlet.basic.MappingServlet'>
       <init-param init='value-a'/>
     </servlet>

     <servlet servlet-name='map-b'
              servlet-class='example.servlet.basic.MappingServlet'>
       <init-param init='value-b'/>
     </servlet>

     <servlet servlet-name='map-c'
              servlet-class='example.servlet.basic.MappingServlet'>
       <init-param init='value-c'/>
     </servlet>

     <!-- an exact match. -->
     <servlet-mapping url-pattern='/exact'
                      servlet-name='map-a'/>

     <!-- a prefix match. -->
     <servlet-mapping url-pattern='/prefix/*'
                      servlet-name='map-b'/>

     <!-- an extension match. -->
     <servlet-mapping url-pattern='*.map'
                      servlet-name='map-c'/>

     <!-- using the invoker (a prefix match). -->
     <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.

URL | Servlet Path | Path Info | Servlet
/exact | /exact | null | servlet-a
/exact/foo | n/a | n/a | 404 Not Found
/prefix | /prefix | null | servlet-b
/prefix/foo | /prefix | /foo | servlet-b
/test.map | /test.map | null | servlet-c
/exact/test.map | /exact/test.map | null | servlet-c
/prefix/test.map | /prefix | /test.map | servlet-b

The example includes a id 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
`MappingServlet()`

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

### MappingServlet

    public MappingServlet()

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