...
The web.xml
configuration file resides in the /WEB-INF/
directory of the (to be) deployed web application. It configures the web server part of the application. The web.xml
file can be used to define which file types may be requested by users, which directories can be accessed, and so on. With regards to JSF, the most important task of web.xml
is to tell the web server that there is such a thing as a Faces Servlet, and that URLs containing a certain pattern should be forwarded to that Faces Servlet. A minimal web.xml
could look like this:
...
The part between the <servlet>
tags tells the application server that it has to instantiate an object of the javax.faces.webapp.FacesServlet
class as a Servlet and name it Faces Servlet
. It will be started at the start up of the application. The part between the <servlet-mapping>
tags tells the web server that any URL starting with /faces/
immediately after the address of the server and the location of the application will be handled by that Servlet.
...
The faces-config.xml
file defines the behavior of the Faces Servlet that is at the heart of a JSF application. Whereas a web.xml
file is generally edited only at the start of a project or when structural changes are made to the application, faces-config.xml
changes all the time, as the application grows. And while web.xml
mostly contains general configuration options, a faces-config.xml
file tends to be more specific to a certain application, as it may contain e.g. navigation details and other application-specific configurations. In JSF 2.0 the presence of a faces-config.xml
file is no longer required, but in earlier JSF versions it is. A minimalistic faces-config.xml
for JSF 1.2 may look like this:
...
To use MyFaces Core as the JSF implementation on a Glassfish 2.x application server, we have to make some additional settings in a GlassFish-specific configuration file—sun-web.xml
. This file has to be in the WEB-INF
folder of our project, along with most of the other configuration files, such as web.xml
and faces-config.xml
. The contents of the file should look like this:
...
This disables the default implementation and forces GlassFish to use MyFaces Core instead. Of course, we have to make sure that the MyFaces Core libraries are added properly to our application and configured correctly, as described in the previous sections.
...