• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet mapping Problem

 
Mohit G Gupta
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 ?
 
Ankit Garg
Sheriff
Posts: 9580
33
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

 
Nidhi Sar
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.

 
Prashant Shiralkar
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic