• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet mapping

 
Sorin Alexandru
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

In the PetStore application, web.xml contains the following mappings:

.... and:


If I navigate in my browser to http://localhost:8087/petstore/faces/catalog.jsp?catid=Cats#feline01,1,
what servlet mappings will be performed: both the FacesServlet (because of the /faces) and the ControllerServlet (because of /catalog)
or just the best match, which is ControllerServlet ?

Also, when I debug the ControllerServlet, I see in the debugger that getRequestURI() is /petstore/catalog and getServletPath() is /catalog. Where is /faces then ?

Thank you,
Best regards,
Sorin
 
Krystian Gor
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorin Alexandru wrote:



I means that every request with URL matching "/faces/*" will be directed to this servlet. There's no "/faces" folder. It's just an expression to match by URLs.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no ambiguity there. The "/" at the beginning of the URL pattern means "root", so a "/faces/catalog/anything" will always route to the Faces Servlet and a "/catalog/faces/anything" will always route to the catalog servlet.

A lot of people don't understand the difference between resources (files and folders) and URLs, because they look so similar and because the default action is to take a URL and convert it into a resource path. But the difference is critical. web.xml does its matching on URLs, not resource paths.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic