URLs with .jsf extension still redirect to .xhtml after FacesServlet removal from web.xml

696 Views Asked by At

I have a web application that originally was a JSF app, but has been migrated to pure HTML/JavaScript. We are now in the progress of eliminating JSF completely.

We had the physical file main.xhtml, which was requested by "main.jsf", where the FacesServlet was declared in web.xml with url-mapping *.jsf.

We have moved the content to main.html, and put a meta-tag REFRESH in main.xhtml to redirect to main.html.

Now the problem is that even if I remove FacesServlet from web.xml, it still redirects the request for main.jsf to main.xhtml. If I rename the file main.xhtml to main.jsf, requesting main.jsf gives a 404, and the server log says it cannot find a file "main.jsp".

Now the question is: If it redirects *.jsf to *.jsp or *.xhtml even when there is no FacesServlet in web.xml, what is responsible for this redirections?

I'm using GlassFish 3.1.2.2.

1

There are 1 best solutions below

0
On BEST ANSWER

When using JSF 2.0+ on a Servlet 3.0+ container, and there's no explicit FacesServlet registration in webapp's own web.xml, then the FacesServlet will during webapp's startup automatically be registered on URL patterns /faces/*, *.faces and *.jsf.

See also its javadoc:

This servlet must automatically be mapped if it is not explicitly mapped in web.xml or web-fragment.xml and one or more of the following conditions are true.

  • A faces-config.xml file is found in WEB-INF

  • A faces-config.xml file is found in the META-INF directory of a jar in the application's classpath.

  • A filename ending in .faces-config.xml is found in the META-INF directory of a jar in the application's classpath.

  • The javax.faces.CONFIG_FILES context param is declared in web.xml or web-fragment.xml.

  • The Set of classes passed to the onStartup() method of the ServletContainerInitializer implementation is not empty.

If the runtime determines that the servlet must be automatically mapped, it must be mapped to the following <url-pattern> entries.

  • /faces
  • *.jsf
  • *.faces

JSF 2.3 will add *.xhtml URL pattern to the set (which is backported in Mojarra 2.2.11).

If you want to stop this behavior, and you can't eliminate the triggers (e.g. still having a faces-config.xml), then your best bet is to explicitly register FacesServlet on *.xhtml in webapp's own web.xml. This will override the default auto registered URL patterns.