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]>

Reply via email to