Kevin Duffey wrote:

> Hey Craig,
>
> Do you happen to know when you put the mapping in web.xml does it mean you
> MUST have a file with the exentions .do in the file system for that to work?
>
> I would think not..but I recall someone saying that it does require a file
> to be in the file system with a name like Login.do for the mapping to work.
>

Not at all.

The mappings you list in web.xml are attempted in the order defined in the servlet
api spec, section 10.1 -- basically, that means trying things in the following
order.  In all cases, the string being tested is that portion of the request URI
that follows the context path.

(1)  exact match to a <url-pattern> string
     that does not have any "*" characters.

(2) longest prefix matching against any
     <url-pattern> string that ends in "/*".

(3) Extension matching against any
     <url-pattern> string that ends in "*.xxx"
     (like *.jsp).

(4) Serve via the default servlet for this
     web application.

If one of the first three rules finds a match, the servlet specified in the mapping
rule is executed and there is no attempt to reference any file by that name.  Only
in the fourth case does there need to be a file -- this is how static files get
served.  It works like this -- assume you make a request for the context-relative
path "/index.html".  None of the first three rules matches, so the default servlet
is called.  It can call request.getPathInfo() to see what file you requested
("/index.html") and then calls getResourceAsStream() to read it.

Craig

PS:  Armed with the above knowledge, you should be able to amaze your friends and
colleagues by knowing the answer to the following trivia question:

Q:  So how do anonymous servlets (those not registered in the web.xml file) work?

A:  The servlet container will generally have some default entries for each web
app,
    including something like the following:

    <servlet>
        <servlet-name>invoker</servlet>
        <servlet-class>...name of the internal class...</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>

As you can see, rule (2) above is used to call the invoker servlet, which (again)
can call request.getPathInfo() to see what servlet class you want.  The invoker
then dynamically loads a new instance of the servlet class (not too different from
loading an action class in a Model 2 system :-), registers it with the servlet
container, and calls its service() method.  Cool, huh?

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to