File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Servlet mapping

Sorin Alexandru

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,
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: 17417

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.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Servlet mapping
It's not a secret anymore!