You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Sterin, Ilya" <Is...@ciber.com> on 2002/12/24 20:16:39 UTC

RE: Reaching the ServletContext from Action class

Are you importing

import javax.servlet.ServletContext;

???

Ilya

-----Original Message-----
From: Fatih Algan [mailto:algan_fatih@yahoo.com]
Sent: Tuesday, December 24, 2002 2:19 PM
To: struts-user@jakarta.apache.org
Subject: Reaching the ServletContext from Action class



   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:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Best way to do database update forms

Posted by "Sterin, Ilya" <Is...@ciber.com>.
Hi, I just wanted to ask for a recommendation on doing say a member update
form.

Do I need two Actions, one for retrieving the data and populating the form,
then forwarding to a jsp page, and one for validating and updating the db?
This is the first thing that came to my mind, so I wondered if someone had a
better solution, if they deem this one not the best:-)  i was planning on
forwarding the update link to the member_show.do servlet first, then it will
forward to jsp page once it populates the form, but that's an issue, do to
below...

Also, I plan on having the update_member jsp page in the member directory,
which will be filtered for logon criteria and if not forwarded to the logon
page, my question is...

Because I need to execute the Servlet which populates the jsp form first and
then it is forwarded to the update_member jsp form, I can't use the filter
since the servlet would already require the logon information.  I can
ofcourse put in a small check in the servlet and forward to logon if needed,
but what about the rest of the servlets that will need such a check, would I
not have the ability to filter those as the jsp pages?

I think the issue goes back to the design of my initial paragraph question,
where the update member functionality might need to be designed differently.

I appreciate any feedback on this.  Thanks a bunch.

Ilya

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>