Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * $Id:,v 1.32 2007/01/29 07:29:01 rlubke Exp $
   * The contents of this file are subject to the terms
   * of the Common Development and Distribution License
   * (the License). You may not use this file except in
   * compliance with the License.
  * You can obtain a copy of the License at
  * or
  * legal/CDDLv1.0.txt. 
  * See the License for the specific language governing
  * permission and limitations under the License.
  * When distributing Covered Code, include this CDDL
  * Header Notice in each file and include the License file
  * at legal/CDDLv1.0.txt.    
  * If applicable, add the following below the CDDL Header,
  * with the fields enclosed by brackets [] replaced by
  * your own identifying information:
  * "Portions Copyrighted [year] [name of copyright owner]"
  * [Name of File] [ver.__] [Date]
  * Copyright 2005 Sun Microsystems Inc. All Rights Reserved
 package javax.faces.webapp;

FacesServlet is a servlet that manages the request processing lifecycle for web applications that are utilizing JavaServer Faces to construct the user interface.

 public final class FacesServlet implements Servlet {


Context initialization parameter name for a comma delimited list of context-relative resource paths (in addition to /WEB-INF/faces-config.xml which is loaded automatically if it exists) containing JavaServer Faces configuration information.

     public static final String CONFIG_FILES_ATTR =


Context initialization parameter name for the lifecycle identifier of the javax.faces.lifecycle.Lifecycle instance to be utilized.

     public static final String LIFECYCLE_ID_ATTR =


Factory for javax.faces.context.FacesContext instances.

     private FacesContextFactory facesContextFactory = null;


The javax.faces.lifecycle.Lifecycle instance to use for request processing.

     private Lifecycle lifecycle = null;


The ServletConfig instance for this servlet.

     private ServletConfig servletConfig = null;


Release all resources acquired at startup time.

     public void destroy() {
         = null;
         = null;
         = null;


Return the ServletConfig instance for this servlet.

    public ServletConfig getServletConfig() {
        return (this.);


Return information about this Servlet.

    public String getServletInfo() {
        return (this.getClass().getName());


Acquire the factory instances we will require.

javax.servlet.ServletException if, for any reason, the startup of this Faces application failed. This includes errors in the config file that is parsed before or during the processing of this init() method.
    public void init(ServletConfig servletConfigthrows ServletException {
        // Save our ServletConfig instance
        this. = servletConfig;
        // Acquire our FacesContextFactory instance
        try {
             = (FacesContextFactory)
        } catch (FacesException e) {
            Throwable rootCause = e.getCause();
            if (rootCause == null) {
                throw e;
            } else {
                throw new ServletException(e.getMessage(), rootCause);
        // Acquire our Lifecycle instance
        try {
            LifecycleFactory lifecycleFactory = (LifecycleFactory)
            String lifecycleId ;
            // First look in the servlet init-param set
            if (null == (lifecycleId = servletConfig.getInitParameter())) {
                // If not found, look in the context-param set 
                lifecycleId = servletConfig.getServletContext().getInitParameter
            if (lifecycleId == null) {
                lifecycleId = .;
             = lifecycleFactory.getLifecycle(lifecycleId);
        } catch (FacesException e) {
            Throwable rootCause = e.getCause();
            if (rootCause == null) {
                throw e;
            } else {
                throw new ServletException(e.getMessage(), rootCause);


Process an incoming request, and create the corresponding response, by executing the request processing lifecycle.

If the request and response arguments to this method are not instances of HttpServletRequest and HttpServletResponse, respectively, the results of invoking this method are undefined.

This method must respond to requests that start with the following strings by invoking the sendError method on the response argument (cast to HttpServletResponse), passing the code HttpServletResponse.SC_NOT_FOUND as the argument.


request The servlet request we are processing
response The servlet response we are creating
Throws: if an input/output error occurs during processing
javax.servlet.ServletException if a servlet error occurs during processing
    public void service(ServletRequest request,
                        ServletResponse response)
        throws IOExceptionServletException {
        // If prefix mapped, then ensure requests for /WEB-INF are
        // not processed.
        String pathInfo = ((HttpServletRequestrequest).getPathInfo();
        if (pathInfo != null) {
            pathInfo = pathInfo.toUpperCase();
            if (pathInfo.startsWith("/WEB-INF/")
                || pathInfo.equals("/WEB-INF")
                || pathInfo.startsWith("/META-INF/")
                || pathInfo.equals("/META-INF")) {
        // Acquire the FacesContext instance for this request
            (.getServletContext(), requestresponse);
        // Execute the request processing lifecycle for this request
        try {
        } catch (FacesException e) {
            Throwable t = e.getCause();
            if (t == null) {
                throw new ServletException(e.getMessage(), e);
            } else {
                if (t instanceof ServletException) {
                    throw ((ServletExceptiont);
                } else if (t instanceof IOException) {
                    throw ((IOExceptiont);
                } else {
                    throw new ServletException(t.getMessage(), t);
        finally {
            // Release the FacesContext instance for this request
New to GrepCode? Check out our FAQ X