Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I initialize custom “application scope” objects for use in a Struts application?

0
Posted

How can I initialize custom “application scope” objects for use in a Struts application?

0

Location: http://www.jguru.com/faq/view.jsp?EID=471960 Created: Aug 8, 2001 Author: Ted Husted (http://www.jguru.com/guru/viewbio.jsp?EID=462042) One way would be to subclass the ActionServlet, to to initialize whatever application scope objects you might need. Just remember to call the super.init() method! A better approach would be to write another servlet, and auto-load both the Struts controller and your own servlet through the web.xml file. The Example application does this to load a “database” servlet, which is then accessed throughout the application. This way you can initialize application-specific things through your specialized servlet, and leave the normal Struts controller servlet alone. In a servlet 2.3 environment (such as Tomcat 4.0), you will also be able to use the new application event listener APIs to catch the contextInitialized() and contextDestroyed() events. This will become the preferred method, once servlet 2.3 containers are widely available.

Related Questions

Thanksgiving questions

*Sadly, we had to bring back ads too. Hopefully more targeted.