A web.xml configuration file in Java

A web.xml configuration file in Java

All J2EE web applications are configured with a web.xml deployment descriptor. It’s a very important file, and it’s good to know something about it.

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE web-app PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN” “http://java.sun.com/dtd/web-app_2_3.dtd”&gt;

<web-app>

<display-name>Hello, World!</display-name>
<description>Welcome to JavaServer Faces</description>

<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
     <servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>

<session-config>
    <session-timeout>30 </session-timeout>
 </session-config>

<welcome-file-list>
    <welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>

</web-app>

<display-name></display-name> – short name displayed by GUI tools

<description></description> – descriptive name about our Web application

<servlet></servlet> – our servlet definition

<servlet-name>Faces Servlet</our-servlet-name> – the name of our servlet

<servlet-class>javax.faces.webapp.FacesServlet</servlet-class> – the class our servlet belongs to

<load-on-startup>1</load-on-startup> – load order on startup (0, 1, 2, etc); lower numbers first, then higher ones; when the value is < 0 or no value, then our servlet is loaded when the web container chooses

<servlet-mapping></our-servlet-mapping> our servlet mapping on URL name

<servlet-name>Faces Servlet</our-servlet-name> the name of our servlet (must be the same in both cases: <servlet></servlet> and <servlet-mapping></servlet-mapping>)

<url-pattern>/faces/*</url-pattern> the name of our servlet mapped to an URL pattern (we use that to get to the servlet in a web browser that is /faces/our-servlet-name)

<session-config></session-config> – session configuration

<session-timeout>30 </session-timeout>– how long your session lasts

<welcome-file-list></welcome-file-list> – welcome files show when no filename is provided in the URL

<welcome-file>faces/index.xhtml</welcome-file> – your welcome file is index.xhtml

Leave a comment