Struts2 doesn't stop you from implementing a ServletContextListener. In fact in the Appfuse Struts2 application there is a StartupListener (extends ServletContextListener) that does what you talk about.
It just so happens that Appfuse also uses Spring to configure its services including its database connections. So in this StartupListener there is some configuration read from web.xml ServletContext context = event.getServletContext(); String something = context.getInitParameter(name_of_paramerter); But it also initializes things like static drop-down lists for HTML selects. It does this by connecting to the database using Spring managed beans. The database related Spring managed beans are configured as such: <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:jdbc.properties</value> </list> </property> </bean> <!-- JNDI DataSource for J2EE environments --> <!--<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/appfuse"/>--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="maxActive" value="100"/> <property name="maxWait" value="1000"/> <property name="poolPreparedStatements" value="true"/> <property name="defaultAutoCommit" value="true"/> </bean> It also uses Hibernate, so there is a SessionFactory bean that references this DataSource bean and then DAO classes that reference the SessionFactory bean, but that is beyond this discussion I think. What you see above is how an external property file is declared and then those values included in configuration of a Spring managed bean. The ServletContextListener gets these Spring beans by doing the following: ServletContext context = event.getServletContext(); ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context); (BasicDataSource) ds = ctx.getBean("dataSource"); The last interesting part of this example/topic is that the listener looks up the list of values from the database and then puts them into the ServletContext to be access later by struts tags. List options = ...some jdbc that returns a list.... context.setAttribute("optionListName",options); Then later on in a page: <s:select list="#attr.optionListName" .... /> (Uses OGNL to get something from the ServletContext) Martin Kindler wrote: > > Hi, > > I am new to Struts2 and stumbling immediately. > > I want to have an initialization routine in my web app which will connect > to a data base etc. at startup time. This routine needs some parameters > (e. g. the path of a config file to be read). How can I access such > external information? > > With Servlets I would normally implement a ServletContextListener which > would get its information as an init-param from web.xml. > But for Struts2 there is no <servlet> spec where I could put it. > > Writing Struts1 applications I typically utilized a plugin which could > read parameters from struts-config.xml. Maybe this is still possible, but > the Struts2 plugin mechanism seems to be too powerful (or just > overwhelming) for me. > > What is the preferred way? > > Thanks > > Martin > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- View this message in context: http://www.nabble.com/-struts2-how-to-configure-the-web-app-tp17273160p17277112.html Sent from the Struts - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]