Mark wrote:

>For example, now that I *finally* got my app to work using servlet mapping,
>I also found if I leave all mapping out of web.xml and have <FORM
>ACTION="servlet/myservlet" METHOD="POST">, Tomcat will still find/run the
>servlet under ..WEB-INF/classes.  Is that by design?
>
Mark,

Congradulations, nice when things work well,

I will say a few things that you can get from an excellent book Java Servlet
Programming by Jason Hunter and William Crawford (O'Reilly).

First, do not assume, because you will be wrong, that / is required in the
mapping pattern.  You are using a particular kind of mapping.

Second, in answer to your question, indeed it is.  I hope my last little
note made that clearer.  I like to keep my applications essentially dark to
the outside world except in very controlled ways, so I put everything inside
WEB-INF except my index.jsp and make all servlets accessible through clever,
;-) , patterns used in servlet mappings.   I use a Model 2 multi-tier
architecture and run EVERYTHING first through a controller servlet that
monitors all outside access.

A general point about web.xml and servlet tags.  Servlets that you want to
be registered with the server and receive special treatment get that through
the web.xml.  That is what the servlet tags are for.  Only one example of
such treatments is that we can set up URL patterns that will invoke the
registered servlet.  There are lots of good reasons for doing this.  For
example, you could use this to have a servlet preplace an existing JSP page
at any given URL, so all bookmarks and links to the page continue to work.
Kewl, eh?  I like to use it to hide things and to thereby enhance security.
You can have your servlets invoked by dinky.html, if you like.

Mappings have varieties:

    1.    Explicit Mappings

             /whatever

            These contain no "wildcards".  This is useful when replacing an
existing page.

    2.    Path Prefix Mappings

            /something/database/*

            These maps always begint with a / and end with a /*.  This
allows a servlet to control an entire virtual hierarchy like a database app.

    3.    Extension Mappings

            *.wm or *.jsp

            These begin with * and handle all requests ending with the
subsequent prefix.  David Geary uses this in his app provided in the 12th
chapter of his new book on taglibs in order to make sure all urls ending in
.do go to his controller ActionServlet of a Model 2 architecture.

    4.    Default Mapping

            /

            This provides the servlet to be used if no other servlet
matches.  You could get the same sort of behavior by /* but this has the
advantage of coming after extension mappings are done.

If there are collisions, the precedence is the order indicated above.

Okay, last thing.  With Tomcat server, server_root/webapps/ROOT is the
default context mapped to the root path "/".  THIS IS IMPORTANT.  ;-)  This
means that servlets placed under the servlets placed under the
server_root/webapps/ROOT/WEB-INF/classes can be accessed using the path
/servlet/HelloWorldExample.  HOWEVER, this default context mapping can be
changed and new mappings can be added by editing the
server_root/conf/server.xml serverwide configuration file.  Other servers
handle this differently.  Okay dokay?





--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to