• 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

servlet and mapping declarations in web.xml

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,
While programming the Servlets and using the web.xml, we write the below format:

<servlet>
<servlet-name>xmlServlet</servlet-name>
<servlet-class>main.programs.XMLServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>xmlServlet</servlet-name>
<url-pattern>/XMLServ</url-pattern>
</servlet-mapping>

My question is why can't the below structure be configured to avoid redundancy?
By putting all the required data under one single tag instead of 2 tags ,i.e the <servlet> and <servlet-mapping> tag.


<servlet>
<servlet-name>xmlServlet</servlet-name>
<servlet-class>main.programs.XMLServlet</servlet-class>
<url-pattern>/XMLServ</url-pattern>
</servlet>

By making this kind of lots of redundant code can be reduced.

Please let me know if there is a reason if it cannot be done and correct me if i am wrong in any sense.

Cheers..
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because the mappings are orthogonal to the servlet declarations, and there can be many mappings for each servlet declaration.
 
keshav pradeep ramanath
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,
Thanks for the quick reply.
Can you please elaborate?

Yes,even if there are many mapping,in my example i am just trying to remove the occurance of the <servlet-name> ,along with the <servlet-mapping> tag as a whole.
With only 1 <servlet-name> can't it be made possible to pick the servlet having a particular URL Pattern?

Thanks in advance..
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What it simply comes down to is that whether you agree with it or not, the XML Schema doesn't allow for such shortcuts, so you can't do it.
 
keshav pradeep ramanath
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,
Thanks for the info..

I do agree with you that the existing XML Schema does not entertain the kind of structure i have shown.
However can it be changed ?
Are there more intricacies involved for not doing this?

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

keshav pradeep ramanath wrote:However can it be changed ?


I guess you can petition the framers of the next version of the Servlet Specification to make such a change. But they're likely to simply ignore such a request. I know I would.
 
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you use annotations instead of XML?
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The whole mechanism is designed to maximize abstraction and flexibility. Although at first glance, it certainly can seem confusing.

Often you only have a simple URL pattern(s) that you want to feed to a servlet, but sometimes you need more. Furthermore, by giving a servlet a logical name instead of pointing the URLs directly to the physical servlet, you have the flexibility to shift URLs to an alternative servlet (for example, a debugging version of the original servlet) and minimise the number of web.xml entries you need to modify to do that on a selective basis.
 
reply
    Bookmark Topic Watch Topic
  • New Topic