• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Servlet mapping Problem  RSS feed

 
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do we placed servlet mapping outside the servlet tag and not inside ?
we do mapping for a specific servlet ,then why so ?
 
Sheriff
Posts: 9643
42
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can map a servlet to more than one paths so if the mapping is separate, you can decide url matching more flexibly by ordering the servlet-mapping declaration in the order you want the servlets to match an incoming request. Something like this
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i still didn't get it

 
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting question. Not sure why the Sun engineers designed it this way, but they could have put the <url-pattern> right inside the <servlet> tag, couldn't they? I don't see a reason why theoretically that wouldn't work. Allowing multiple <url-pattern> tags could give the flexibility of mapping different kinds of urls to the same servlet, that Ankit is talking about.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably, from maintainability viewpoint, they kept <url-pattern> tag separate from <servlet>. If its a part of <servlet>, imagine what you'd need to do if you later want a url path to be handled by a different servlet (existing or a new one). You'd have to delete the <url-pattern> from the current <servlet> and make a new entry in the other <servlet>. Instead, keeping this tag in a separate <servlet-mapping> tag gives you the ease of maintenance by being able to change just the name of the servlet without touching other parts in the descriptor.
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!