struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fatih Algan <algan_fa...@yahoo.com>
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

<data-sources>
<data-source>
<set-property property="driverClass"
value="COM.ibm.db2.jdbc.app.DB2Driver"/>
<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"/>
</data-source>
 </data-sources>

 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)  
context.getAttribute(Action.DATA_SOURCE_KEY);

 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.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message