JSF web.xml URI Mappings

I've come across something which I need someone to explain. It's not something that I would advocate doing but the behaviour interests me. I have 2 servlet mappings for the FacesServlet in the web.xml.

<servlet-mapping>

<servlet-name>FacesServlet</servlet-name>

<url-pattern>/jsf/*</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>FacesServlet</servlet-name>

<url-pattern>*.faces</url-pattern>

</servlet-mapping>

If I use the uri <web-context>/jsf/index.faces using Tomcat 6.0.10 the request never returns the index.jsp page.

If I remove one either one of the servlet mappings, the uri <web-context>/jsf/index.faces returns the index.jsp page correctly.

It seems that having 2 mappings that are both applicable to the uri <web-context>/jsf/index.faces causes an issue.

Just wonder if anyone is able to explain this behaviour. It is a problem with JSF or Servlet/JSPs in general. I would have thought that some precedence ordering would have been applicable and the request would be fulfilled even when both servlet mappings are present.

Thanks

[1236 byte] By [slenno02a] at [2007-11-27 4:32:00]
# 1
My guess would be the container and not JSF.You could easily validate by using a simple helloworld servlet.
rlubkea at 2007-7-12 9:41:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi,

Thanks for the reply. I tested it using a simple servlet and mapping and it works fine. Therefore I think the issue may lie with the JSF RI. I'm using Glassfish 1.2_04 api and implementation. In fact if I use the following mapping the request it never fulfilled.

<servlet-mapping>

<servlet-name>FacesServlet</servlet-name>

<url-pattern>*.jsp</url-pattern>

</servlet-mapping>

Does anyone have this problem or know why it occurs.

Thanks

slenno02a at 2007-7-12 9:41:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
yes, if you map the FacesServlet to *.jsp, then any JSP in the application will no longer work.
rlubkea at 2007-7-12 9:41:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Regardless, invoking a single servlet through two mappings isn't suggested. Is there a reason you're doing that?
rlubkea at 2007-7-12 9:41:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Why is that so? Why does no JSP work if mapped to the Faces Servlet?No there is no reason why I'm doing that and as I said previous I wouldn't advocate doing this. I'm just curious and educating myself.Thanks for your help.
slenno02a at 2007-7-12 9:41:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
The container has an internal mapping of *.jsp to points to the JspServlet (effectively the JSP engine). If you override the default mapping, as you have done in your last example, then JSPs won't work.
rlubkea at 2007-7-12 9:41:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
.Message was edited by: rlubke
rlubkea at 2007-7-12 9:41:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Thanks for this. Looking at this I can see why. However one things that still has me puzzled is the following.

I have 2 servlet mappings (this is for experimental purposes only)

<servlet-mapping>

<servlet-name>FacesServlet</servlet-name>

<url-pattern>/faces/*</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>FacesServlet</servlet-name>

<url-pattern>*.faces</url-pattern>

</servlet-mapping>

When I submit the url http://localhost:8080/jsf/faces/index.faces the application totally flips out and the request is never serviced. There is an infinite wait. This is because there are 2 mappings which relate to this request. Remove one of the mappings and the application works fine.

I tried a similar mapping using plain servlets ie;

<servlet-mapping>

<servlet-name>TestServlet</servlet-name>

<url-pattern>/test/*</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>TestServlet</servlet-name>

<url-pattern>*.jsp</url-pattern>

</servlet-mapping>

I submitted the url http://localhost:8080/example/test/index.jsp and it works fine. There is something different occurring in JSF. Does anyone know what is could be?

Thanks

slenno02a at 2007-7-12 9:41:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
Hi,I've worked out exactly what is happening. I turned the debug on the JSPServlet and was able to determine how this was working.Thanks for your help.
slenno02a at 2007-7-12 9:41:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...