• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

another HFSJ question page 620

 
justine mills
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?
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 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...
 
Abdul Rahman
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?
 
Michel Pires
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic