Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

another HFSJ question page 620

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which servlet will container choose given the DD servlet mappings and client request shown?




http://localhost:8080/Map Test/fooStuff/bar/blue.do



My answer if Two but correct answer in Three. Anyone care to explain?
 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Justine three is the correct answer. Two maps to /fooStuff/bar so it won't match anything other than /fooStuff/bar. Since three is mapped to /fooStuff/*, so it will map to anything that starts with /fooStuff, but if a request for /fooStuff/bar comes, two will be matched as it is an exact match. For any other request starting with /fooStuff, Three will be mapped by the container. If Two was mapped to /fooStuff/bar/*, then on a request for /fooStuff/bar/blue.do, Two would have been chosen by the container...
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

http://localhost:8080/Map Test/fooStuff/bar/blue.do



servlet two will match till http://localhost:8080/Map Test/fooStuff/bar

anything beyond this will match to servlet three http://localhost:8080/Map Test/fooStuff/bar/blue.do because the servlet three has a wild card expression and so it matches the longest path.

Hope that answers.
 
justine mills
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the explanation. Now, if there is no Three mapping, and we still have the same request coming... will it be served on Two?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


<servlet-mapping>
<servlet-name>Two</servlet-name>
<url-pattern>/fooStuff/bar</url-pattern>
</servlet-mapping>


is like saying the url ../TheWebApp/fooStuff/bar is mapped to servlet Two.

And your request ../TheWebApp/fooStuff/bar/blue.do != ../TheWebApp/fooStuff/bar
It will not match the url-pattern and at the end, it will not be mapped to servlet Two.
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic