Request.getSession().getServletContext();

Edgar

-----Original Message-----
From: Pete Serafin [mailto:[EMAIL PROTECTED]] 
Sent: Saturday, December 14, 2002 11:57 AM
To: 'Struts Users Mailing List'; 'Struts Users Mailing List'
Subject: RE: Finding app context in action class???


Edgar,
 
I think you misunderstood me.  I meant is there a similar way to access
the "application context" in the same way you can access the session.  I
know request.getSession returns a session object .... how do I get an
application object?  In a jsp, its referenced as "application".  How is
it referenced in the acition class?

        -----Original Message----- 
        From: Edgar P. Dollin [mailto:[EMAIL PROTECTED]] 
        Sent: Sat 12/14/2002 10:42 AM 
        To: 'Struts Users Mailing List' 
        Cc: 
        Subject: RE: Finding app context in action class???
        
        

        Request.getSession(); ????
        
        -----Original Message-----
        From: Pete Serafin [mailto:[EMAIL PROTECTED]]
        Sent: Saturday, December 14, 2002 11:32 AM
        To: '[EMAIL PROTECTED]'
        Subject: RE: Finding app context in action class???
        
        
        This is close, but I am hoping to accomplish with just an Action
class.
        I dont want to extend my class into any form of ActionServlet ,
servlet,
        
        or anything like that.  Is it possible to get access from an
Action page
        the way you can get access to the session?
        
                -----Original Message-----
                From: D, Gopinath (MED) [mailto:[EMAIL PROTECTED]]
                Sent: Sat 12/14/2002 1:26 AM
                To: Pete Serafin
                Cc:
                Subject: FW: Finding app context in action class???
               
               
        
                This is how i've used the context in my application. It
loads
        objects(say
                collections) into servletContext.
               
                In struts you would refer them as :
                                <html:select property="severity">
                                        <html:options
name="severityList"/>
                                </html:select>
               
                Hope this is what you are looking for ?? Any comments..
               
                /*
                * ContextTest.java
                */
                package examples.struts.action;
               
                import java.io.IOException;
                import javax.servlet.RequestDispatcher;
                import javax.servlet.ServletException;
                import javax.servlet.http.HttpServletRequest;
                import javax.servlet.http.HttpSession;
                import javax.servlet.http.HttpServletResponse;
                import javax.servlet.ServletContext;
                import org.apache.struts.action.Action;
                import org.apache.struts.action.ActionServlet;
                import java.util.Vector;
                import java.util.ArrayList;
               
                /**
                 * This ContextTest loads the objects into
servletcontext, which
        could be
                used in the applications.
                 * Say your objects has to be shared in your
applications. this
        class the
                cache objects into session from this servlet context.
                 * This servlet is loaded on startup on the server. Ref
web.xml
                 * <p>
                 * The init() method loads all cache objecst into
        servletContext.
                 * The destory() method removes all cache objects
reference from
                servletContext.
                 * @author
                 */
               
                public class ContextTest extends ActionServlet {
                      
                        ServletContext servletContext = null;
               
                        /**
                         * Init method loads all cacheobjects into
        servletContext.
                         */
               
                        public void init() throws
javax.servlet.ServletException
        {
                              
                                super.init();
               
                                ArrayList aSeverity     = new
ArrayList();
               
                            System.out.println("Action Servlet:Init -
Begin");
               
                                Vector vSeverity =
        SeverityCache.getInstance().getCache();
                                int sevSize = vSeverity.size();
                                for(int k=0; k<sevSize; k++){
                                        SeverityObject sevObj =
                (SeverityObject)vSeverity.elementAt(k);
        
aSeverity.add(sevObj.getValue()+"  -
                "+sevObj.getShortName(););
                                }
                            System.out.println("Action Servlet - Loaded
        SeverityCache");
               
                                servletContext = getServletContext();
               
        servletContext.setAttribute("severityList",aSeverity);
                              
                                System.out.println("Action Servlet:Init
- End");
                        }
               
                        /**
                         * Destroy removes all cache objects reference
from
        servletContext.
                         */
               
                        public void destroy() {
                            System.out.println("ActionServlet:Destroy -
Begin");
                                super.destroy();
               
        servletContext.setAttribute("severityList",null);
                            System.out.println("ActionServlet:Destroy -
End");
                        }
               
                    protected void process(HttpServletRequest req,
        HttpServletResponse res)
                throws ServletException, java.io.IOException
                    {
                        System.out.println("Process");
                        super.process(req,res);
                    }
                }
                -----Original Message-----
                From: Pete Serafin [mailto:[EMAIL PROTECTED]]
                Sent: Saturday, December 14, 2002 12:28 PM
                To: [EMAIL PROTECTED]
                Subject: Finding app context in action class???
               
               
                Its been a while since Ive had to write code to access
the
        application
                context from a struts action class and I have forgotten
how to
        do so.  Can
                anyone give point me in the right direction as to how to
do
        this?
               
               
                "THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS
INTENDED ONLY
        FOR THE
                ADDRESSEE and may contain confidential and privileged
        information.
                If the reader of this message is not the intended
recipient,
                you are notified that any dissemination, distribution or
copy of
        this
                communication is strictly Prohibited.
                If you have received this message by error, please
notify us
                immediately, return the original mail to the sender and
delete
        the
                message from your system."
               
               
        
        
        
        
        --
        To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
        For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
        
        



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to