Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URL pattern for servlet mapping

 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Trying to test the URL mapping. The entries in the web.xml file are



Then enter the URL in browser as
http://localhost:8080/tutorial/pattern1/

The Tomcat select the NewServlet3. This is right.

Then enter the URL in browser as

http://localhost:8080/tutorial/pattern1

The Tomcat select the NewServlet2.
Why not NewServlet1 ??? Any specific reason ???

Thanks
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think
if u have more than one servlet mappings that have the same url-pattern, tomcat picks the one that appears at the last
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,

Is it mean that this behavior is container specific. I did not find anything on this in Servlet Specification .

Thanks
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Narendra,
Though there is nothing specific about this in spec, In general container behaviour would be like overriding the old value with new value if the key (url-pattern in this case) is same. Tomcat container would have used a data structure HashMap(or similar to this) where upon parsing it keeps loading all values. Since the url-pattern key is already used, upon next entry it overrides the value..
But in general we dont define two same url patterns with one resource right unless that is done mistakenly!!
HTH.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rizwan,

Thank for the explanation. Really we do not use such mapping. I did this only for the testing purpose. It is like the multiple init parameters in the context param or servlet param. It takes the last value in tomcat.

Anybody tested it on other containers ?

Thanks
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not find anything on this in Servlet Specification .[/quote[
If its not on the servlet spec, then it wont be on the exam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic