Servlet Mapping - What's the point?

Discussion in 'Java' started by Fran Cotton, Aug 7, 2003.

  1. Fran Cotton

    Fran Cotton Guest

    What is the point in servlet mapping ( <servlet-mapping> ) ? Even if I have
    200 servlets in my web app sitting in a variety of package hierarchy levels,
    surely the following kind of web.xml entries should do:

    <servlet>
    <servlet-name>amendUser</servlet-name>
    <servlet-class>/com.blah.boo.AmendUserServlet</servlet-class>
    </servlet>

    And so on for each servlet. Why not simply give each servlet a different
    name and map each name to a different servlet class? Am I being thick? Why
    the mapping??? The URL will point to the web app context + the servlet name
    and the container knows where to find web.xml and it knows that the mapped
    classes all live under classes!!??? Is the deployment setup over engineered,
    or is functionality being offered that is typically of no use, or am I
    missing something really obvious?
     
    Fran Cotton, Aug 7, 2003
    #1
    1. Advertising

  2. Fran Cotton

    Ben_ Guest

    In IBM WebSphere, there is a feature for that (serve servlet by class name),
    which implements what you describe (name of the servlet to invoke is
    retrieved automatically from the URI path). It's not that difficult to
    reimplement if you miss the feature in your web container.

    There are several reason not to proceed like this (except durin
    development), among which:
    .. security: do you want to allow anyone to be able to invoke whatever
    servlet even those you didn't intend to be publicly usable
    .. maintainance: what if you want to replace a page with another servlet (->
    broken links)
    .. information leakage: do you want to show the technology you use so
    blatantly (in the URL) on your web site

    Of course, when you have tons of servlets to map, it might be a burden. But
    then you can automate web.xml build with Ant.
     
    Ben_, Aug 8, 2003
    #2
    1. Advertising

  3. Fran Cotton

    Adam Maass Guest

    "Fran Cotton" <a@b> wrote in message
    news:...
    > What is the point in servlet mapping ( <servlet-mapping> ) ? Even if I

    have
    > 200 servlets in my web app sitting in a variety of package hierarchy

    levels,
    > surely the following kind of web.xml entries should do:
    >
    > <servlet>
    > <servlet-name>amendUser</servlet-name>
    > <servlet-class>/com.blah.boo.AmendUserServlet</servlet-class>
    > </servlet>
    >
    > And so on for each servlet. Why not simply give each servlet a different
    > name and map each name to a different servlet class? Am I being thick? Why
    > the mapping??? The URL will point to the web app context + the servlet

    name
    > and the container knows where to find web.xml and it knows that the mapped
    > classes all live under classes!!??? Is the deployment setup over

    engineered,
    > or is functionality being offered that is typically of no use, or am I
    > missing something really obvious?
    >
    >


    Perhaps over-engineered, I agree.

    But the point is: give a symbolic name to each servlet. This symbolic name
    is, effectively, short-hand for the full class name. (What happens if you
    move the servlet class into a different package?) Now you can do nifty
    things like look up all the servlets that make up a webapp by their symbolic
    names, rather than having to know their class names. (The class name is,
    after all, just an implementation detail.)

    Servlet-mapping entries simply map a URI to a servlet symbolic name. You can
    even map the same servlet multiple times, to different URIs. This is
    interesting if you have servlet filters in place -- one of the mappings
    could be a filtered version, and another unfiltered.


    These are obscure kinds of things. I would wager that 99% of applications
    won't make use of them.


    -- Adam Maass
     
    Adam Maass, Aug 8, 2003
    #3
  4. "Fran Cotton" <a@b> writes:

    > What is the point in servlet mapping ( <servlet-mapping> ) ?


    To map one or more URL patterns to a servlet, e.g. *.gif to
    ImageProducerServlet.

    > And so on for each servlet. Why not simply give each servlet a
    > different name and map each name to a different servlet class?


    Because that would limit the way servlets could be used. The first
    Servlet API used a single 'web-app' called "servlets" with the class
    names directly underneath - no web-xml at all.

    > The URL will point to the web app context + the servlet name


    Why should this be the only option?
     
    Tor Iver Wilhelmsen, Aug 8, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Albretch
    Replies:
    2
    Views:
    985
    William Brogden
    Jul 11, 2003
  2. Fran Cotton

    Servlet URL Mapping Evil!

    Fran Cotton, Jul 25, 2003, in forum: Java
    Replies:
    0
    Views:
    3,385
    Fran Cotton
    Jul 25, 2003
  3. Troy Makaro

    simple servlet-mapping question

    Troy Makaro, Aug 27, 2003, in forum: Java
    Replies:
    0
    Views:
    329
    Troy Makaro
    Aug 27, 2003
  4. circuit_breaker
    Replies:
    2
    Views:
    2,081
    Jack Jia
    Apr 4, 2004
  5. Saraswati lakki
    Replies:
    0
    Views:
    1,415
    Saraswati lakki
    Jan 6, 2012
Loading...

Share This Page