aspose file tools*
The moose likes JSF and the fly likes Servlet mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Servlet mapping" Watch "Servlet mapping" New topic
Author

Servlet mapping

Sorin Alexandru
Greenhorn

Joined: Nov 30, 2008
Posts: 28
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

Joined: Jan 11, 2011
Posts: 30
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

Joined: Jun 25, 2001
Posts: 16011
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlet mapping