• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why servlet - mapping?

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to Servlets...and my question is why is servlet-mapping required in web.xml ...whe i use <form action=servletclassname > from the .html file, what is the necessity of < servlet-mapping > tag when i can direct all the requests from the <form action> tag of the .html file...please throw some light
thanks
Pradeep
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Refering to a servlet by its class name is not the preferred way to access a servlet. By default, many servlet containers don't support this behaviour.

Some of the problems with using this servlet is that
  • all servlets are available if you use this. It means you have to delete a servlet to 'disable' it. People may be able to access servlets you don't intend just by knowing its name.
  • it only allows a one to one mapping between URLs and servlet classes. If you had a servlet that did the same thing but behaved slightly differently depending on the mapping location, this wouldn't be possible using the classname.
  • there are other parts of the Servlet API that use the mapped name of the srevlet. I have no idea whether they work correctly, but you wouldn't know until you tried, and it would be unfortunate if you found a feature didn't work until it was too late to back out.

  • These are just some differences off the top of my head, but there may also be an official explaination. I belive that some containers don't support referring to servlets by class name at all.

    Dave
     
    Ranch Hand
    Posts: 5093
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    to illustrate the second point, we have a single servlet that depending on the name it's called with looks up a context param from its mapping and loads a configuration which tells it what to do.
    Before I built that servlet the practice was to generate a new servlet where the only difference between the (at that moment already dozens, would be literally hundreds now) classes was the name of the configfile to be used.
    The mapping would still be required in order to give decent looking URLs...
     
    Author and all-around good cowpoke
    Posts: 13078
    6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sun's intent with the servlet and JSP APIs is to allow you to create a "web application" that is completely independent of all other web applications on a server, yet is flexible in terms of configuring without changing the source code. Thats why web.xml provides so many features.
    Bill
     
    reply
      Bookmark Topic Watch Topic
    • New Topic