Class FacesServlet
- java.lang.Object
- 
- jakarta.faces.webapp.FacesServlet
 
- 
- All Implemented Interfaces:
- Servlet
 
 public final class FacesServlet extends Object implements Servlet FacesServlet is a Jakarta Servlet servlet that manages the request processing lifecycle for web applications that are utilizing Jakarta Faces to construct the user interface. If the application is running in a Jakarta Servlet 3.0 (and beyond) container, the runtime must provide an implementation of the ServletContainerInitializerinterface that declares the following classes in itsHandlesTypesannotation.- FacesConfig
- ResourceDependencies
- ResourceDependency
- jakarta.faces.bean.ManagedBean
- FacesComponent
- UIComponent
- Converter
- FacesConverter
- ListenerFor
- ListenersFor
- FacesBehaviorRenderer
- Renderer
- FacesValidator
- Validator
 This Jakarta Servlet servlet must automatically be mapped if it is not explicitly mapped in web.xmlorweb-fragment.xmland one or more of the following conditions are true.- 
 A faces-config.xmlfile is found inWEB-INF
- 
 A faces-config.xmlfile is found in theMETA-INFdirectory of a jar in the application's classpath.
- 
 A filename ending in .faces-config.xmlis found in theMETA-INFdirectory of a jar in the application's classpath.
- 
 The jakarta.faces.CONFIG_FILEScontext param is declared inweb.xmlorweb-fragment.xml.
- 
 The Setof classes passed to theonStartup()method of theServletContainerInitializerimplementation 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
- *.xhtml
 Note that the automatic mapping to *.xhtmlcan be disabled with the context paramDISABLE_FACESSERVLET_TO_XHTML_PARAM_NAME.This class must be annotated with jakarta.servlet.annotation.MultipartConfig. This causes the Jakarta Servlet container in which the Jakarta Faces implementation is running to correctly handle multipart form data.Some security considerations relating to this class The topic of web application security is a cross-cutting concern and every aspect of the specification address it. However, as with any framework, the application developer needs to pay careful attention to security. Please consider these topics among the rest of the security concerns for the application. This is by no means a complete list of security concerns, and is no substitute for a thorough application level security review. Prefix mappings and the FacesServletIf the FacesServletis mapped using a prefix<url-pattern>, such as<url-pattern>/faces/*</url-pattern>, something must be done to prevent access to the view source without its first being processed by theFacesServlet. One common approach is to apply a <security-constraint> to all facelet files and flow definition files. Please see the Deployment Descriptor chapter of the Jakarta Servlet Specification for more information the use of <security-constraint>.Allowable HTTP Methods The Jakarta Faces Specification only requires the use of the GET and POST http methods. If your web application does not require any other http methods, such as PUT and DELETE, please consider restricting the allowable http methods using the <http-method> and <http-method-omission> elements. Please see the Security sections of the Jakarta Servlet Specification for more information about the use of these elements. 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringAUTOMATIC_EXTENSIONLESS_MAPPING_PARAM_NAMETheServletContextinit parameter consulted by the runtime to tell if the automatic mapping of theFacesServletto the extensionless variant (without*.xhtml) should be enabled.static StringCONFIG_FILES_ATTRContext initialization parameter name for a comma delimited list of context-relative resource paths (in addition to/WEB-INF/faces-config.xmlwhich is loaded automatically if it exists) containing Jakarta Faces configuration information.static StringDISABLE_FACESSERVLET_TO_XHTML_PARAM_NAMETheServletContextinit parameter consulted by the runtime to tell if the automatic mapping of theFacesServletto the extension*.xhtmlshould be disabled.static StringLIFECYCLE_ID_ATTRContext initialization parameter name for the lifecycle identifier of theLifecycleinstance to be utilized.
 - 
Constructor SummaryConstructors Constructor Description FacesServlet()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()Release all resources acquired at startup time.ServletConfiggetServletConfig()Return theServletConfiginstance for this servlet.StringgetServletInfo()Return information about this Servlet.voidinit(ServletConfig servletConfig)Acquire the factory instances we will require.voidservice(ServletRequest req, ServletResponse resp)Process an incoming request, and create the corresponding response according to the following specification.
 
- 
- 
- 
Field Detail- 
CONFIG_FILES_ATTRpublic static final String CONFIG_FILES_ATTR Context initialization parameter name for a comma delimited list of context-relative resource paths (in addition to /WEB-INF/faces-config.xmlwhich is loaded automatically if it exists) containing Jakarta Faces configuration information.- See Also:
- Constant Field Values
 
 - 
LIFECYCLE_ID_ATTRpublic static final String LIFECYCLE_ID_ATTR Context initialization parameter name for the lifecycle identifier of the Lifecycleinstance to be utilized.- See Also:
- Constant Field Values
 
 - 
DISABLE_FACESSERVLET_TO_XHTML_PARAM_NAMEpublic static final String DISABLE_FACESSERVLET_TO_XHTML_PARAM_NAME The ServletContextinit parameter consulted by the runtime to tell if the automatic mapping of theFacesServletto the extension*.xhtmlshould be disabled. The implementation must disable this automatic mapping if and only if the value of this parameter is equal, ignoring case, totrue.If this parameter is not specified, this automatic mapping is enabled as specified above. - See Also:
- Constant Field Values
 
 - 
AUTOMATIC_EXTENSIONLESS_MAPPING_PARAM_NAMEpublic static final String AUTOMATIC_EXTENSIONLESS_MAPPING_PARAM_NAME The ServletContextinit parameter consulted by the runtime to tell if the automatic mapping of theFacesServletto the extensionless variant (without*.xhtml) should be enabled. The implementation must enable this automatic mapping if and only if the value of this parameter is equal, ignoring case, totrue.If this parameter is not specified, this automatic mapping is not enabled. - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
initpublic void init(ServletConfig servletConfig) throws ServletException Acquire the factory instances we will require. - Specified by:
- initin interface- Servlet
- Parameters:
- servletConfig- a- ServletConfigobject containing the servlet's configuration and initialization parameters
- Throws:
- 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.
- See Also:
- UnavailableException,- Servlet.getServletConfig()
 
 - 
servicepublic void service(ServletRequest req, ServletResponse resp) throws IOException, ServletException Process an incoming request, and create the corresponding response according to the following specification. If the requestandresponsearguments to this method are not instances ofHttpServletRequestandHttpServletResponse, respectively, the results of invoking this method are undefined.This method must respond to requests that contain the following strings by invoking the sendErrormethod on the response argument (cast toHttpServletResponse), passing the codeHttpServletResponse.SC_NOT_FOUNDas the argument./WEB-INF/ /WEB-INF /META-INF/ /META-INFIf none of the cases described above in the specification for this method apply to the servicing of this request, the following action must be taken to service the request. Acquire a FacesContextinstance for this request.Acquire the ResourceHandlerfor this request by callingApplication.getResourceHandler(). CallResourceHandler.isResourceRequest(jakarta.faces.context.FacesContext). If this returnstruecallResourceHandler.handleResourceRequest(jakarta.faces.context.FacesContext). If this returnsfalse, callLifecycle.attachWindow(jakarta.faces.context.FacesContext)followed byLifecycle.execute(jakarta.faces.context.FacesContext)followed byLifecycle.render(jakarta.faces.context.FacesContext). If aFacesExceptionis thrown in either case, extract the cause from theFacesException. If the cause isnullextract the message from theFacesException, put it inside of a newServletExceptioninstance, and pass theFacesExceptioninstance as the root cause, then rethrow theServletExceptioninstance. If the cause is an instance ofServletException, rethrow the cause. If the cause is an instance ofIOException, rethrow the cause. Otherwise, create a newServletExceptioninstance, passing the message from the cause, as the first argument, and the cause itself as the second argument.The implementation must make it so FacesContext.release()is called within a finally block as late as possible in the processing for the Jakarta Faces related portion of this request.- Specified by:
- servicein interface- Servlet
- Parameters:
- req- The Jakarta Servlet request we are processing
- resp- The Jakarta Servlet response we are creating
- Throws:
- IOException- if an input/output error occurs during processing
- ServletException- if a Jakarta Servlet error occurs during processing
 
 - 
destroypublic void destroy() Release all resources acquired at startup time. 
 - 
getServletConfigpublic ServletConfig getServletConfig() Return the ServletConfiginstance for this servlet.- Specified by:
- getServletConfigin interface- Servlet
- Returns:
- the ServletConfigobject that initializes this servlet
- See Also:
- Servlet.init(jakarta.servlet.ServletConfig)
 
 - 
getServletInfopublic String getServletInfo() Return information about this Servlet. - Specified by:
- getServletInfoin interface- Servlet
- Returns:
- a Stringcontaining servlet information
 
 
- 
 
-