struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fatih Algan <>
Subject Reaching the ServletContext from Action class
Date Tue, 24 Dec 2002 19:19:16 GMT

   Hello, I'm a struts newbie, so my question may seem
somewhat simple or silly. I'm trying to learn how to
use the struts JDBC Connection Pooling facility.
Here's what I've done

 1.Defined a datasource in struts-config.xml

<set-property property="driverClass"
<set-property property="url" value="jdbc:db2:struts"/>
<set-property property="maxcount" value="5"/>
<set-property property="mincount" value="1"/>
<set-property property="user" value="db2admin"/>
<set-property property="password" value="db2admin"/>

 2.Created my Action class:

 3.Try to reach to SefvletContext from within the
action class to get the DataSource object from
ServletContext like following;

 ServletContext context = servlet.getServletContext();
 DataSource dataSource = (DataSource)  

 However the ServletContext is out of the scope of
Action class and is not visible. I could not find any
methods to get the ServletContext. My questions are;

 1.Isn't it weird that the framework does not let me
reach the ServletContext? Is there a way to get the
ServletContext from within Action class?

 2.What is the preffered and best way to get a
reference to the DataSource? 

  Thanks in advance...


Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message