Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

URL pattern for servlet mapping

 
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
 
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
 
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

 
Paper jam tastes about as you would expect. Try some on this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic