Start Initialization

Problem

Often it is desirable to execute an method or to put an object into application scope during the start of an JSF application. Former this has been done in the methode HttpServlet.init() which is not possible in an JSF application.

Solution

Registration of a second servlet, which just does all neccessary initialization for the web application. The parameter load-on-startup in the file web.xml defines, that the initialization servlet starts before the JSF servlet.

<servlet> <servlet-name>JSF Initialization Servlet</servlet-name> <servlet-class>de.icoding.controller.InitServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet>

There is no servlet mapping defined for the initialization servlet.

Use the method ServletContext.setAttribute(key,object); in the intialization servlet to put special objects into the application scope. It is also possible here to start Scheduler in separate Threads.

Resources

[1] JSF 1.2
[2] web.xml

Johannes Hammoud Start Initialization 07.06.2008

I Coding : Community about Java programing

Language German+-

Java JSF JavaScript HTML CSS NetBeans GlassFish MySQL

Imprint

Visits
6279811
Today
7133