You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Anjib Mulepati <an...@hotmail.com> on 2011/11/18 20:54:45 UTC
Servlet init() equivalent in Struts 1.3.8
Hi All,
I am trying to put some database configuration code in the Struts
application. This is the code for loading context parameter, configure
database parameter and locate the service.
Usually we put this code in init() method of servlet but I am confuse
where I can put this piece of code in Struts. This is basically one time
thing.
Thanks,
Anjib
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Servlet init() equivalent in Struts 1.3.8
Posted by "Givler, Eric" <eg...@pa.gov>.
You could create these objects at startup via a Listener (defined in web.xml) and available as part of the ServletContext as attributes.
You could also wire them together via Spring and gain access via Spring's WebApplicationContext (I think that's what it's called).
Eric
-----Original Message-----
From: Anjib Mulepati [mailto:anjibcs@hotmail.com]
Sent: Friday, November 18, 2011 2:55 PM
To: Struts Users Mailing List
Subject: Servlet init() equivalent in Struts 1.3.8
Hi All,
I am trying to put some database configuration code in the Struts
application. This is the code for loading context parameter, configure
database parameter and locate the service.
Usually we put this code in init() method of servlet but I am confuse
where I can put this piece of code in Struts. This is basically one time
thing.
Thanks,
Anjib
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Servlet init() equivalent in Struts 1.3.8
Posted by Johannes Geppert <jo...@apache.org>.
You can use your own Struts2 FilterDispatcher to solve this.
Like this Example which is loading Configs via an SpringDAO and put it into
the Application Scope:
public class FilterDispatcher extends StrutsPrepareAndExecuteFilter {
private static final Log log = LogFactory.getLog(FilterDispatcher.class);
private ConfigDAO configDAO;
public void init(FilterConfig filterConfig) throws ServletException
{
super.init(filterConfig);
log.info("Init Application Configuration");
XmlWebApplicationContext xwac = (XmlWebApplicationContext)
filterConfig.getServletContext().getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
configDAO = ConfigDAO.getFromApplicationContext(xwac);
List<Config> configs = configDAO.findApplicationConfig();
for (Config c : configs)
{
filterConfig.getServletContext().setAttribute(c.getName(),
c.getValue());
}
}
}
Johannes
-----
web: http://www.jgeppert.com
twitter: http://twitter.com/jogep
--
View this message in context: http://struts.1045723.n5.nabble.com/Servlet-init-equivalent-in-Struts-1-3-8-tp5005400p5006530.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org