You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Suresh Addagalla <su...@wipro.com> on 2003/01/09 07:48:10 UTC
Application scope variables
Hi,
I have a few options for storing application level data, and need your
opinions on deciding on a strategy.
My requirement is to load a couple of properties files in the
application startup and to be able to access them across all classes and
JSPs in the web application.
1. Using the ServletContext of ActionServlet
2. Using the pageContext of JSP (PageContext.APPLICATION_SCOPE)
3. Using JSTL <c:set> tag (Does Struts provide a similar tag?)
4. Any other..
If I use 2 or 3, will I able able to access a property in, say, the
execute method of an Action class? What's the best way to do this?
Thanks,
Suresh
RE: Application scope variables
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Fri, 17 Jan 2003, Suresh Addagalla wrote:
> Date: Fri, 17 Jan 2003 19:29:45 +0530
> From: Suresh Addagalla <su...@wipro.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
> suresh.addagalla@wipro.com
> To: 'Struts Users Mailing List' <st...@jakarta.apache.org>
> Cc: 'Craig R. McClanahan' <cr...@apache.org>
> Subject: RE: Application scope variables
>
> Hi,
>
> Thanks for the suggestion. Can someone outline the procedure for storing
> ServletContext attributes through a strust plug-in? I really couldn't
> find much help on the web to start working on the plug-in related
> things.
>
public class MyPlugIn implements PlugIn {
public void init(ActionServlet servlet, ModuleConfig config)
throws ServletException {
servlet.getServletContext().setAttribute
("foo", "This is the value for servlet context attribute 'foo'");
}
public void destroy() { }
}
> Thanks,
> Suresh
>
Craig
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Application scope variables
Posted by Suresh Addagalla <su...@wipro.com>.
Hi,
Thanks for the suggestion. Can someone outline the procedure for storing
ServletContext attributes through a strust plug-in? I really couldn't
find much help on the web to start working on the plug-in related
things.
Thanks,
Suresh
>-----Original Message-----
>From: Craig R. McClanahan [mailto:craigmcc@apache.org]
>Sent: Thursday, January 09, 2003 12:36 PM
>To: Struts Users Mailing List; suresh.addagalla@wipro.com
>Subject: Re: Application scope variables
>
>
>
>
>My recommendation is to set up shared stuff like this as servlet
context attributes, either in a PlugIn (Struts 1.1) or a
ServletContextListener (Servlet 2.3). Anything stored as servlet context
attributes is instantly available as application scope beans in a JSP
page, through standard JSP tags, through PageContext.APPLICATION_SCOPE,
or any other way you want to do it.
>
>Craig
Re: Application scope variables
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Thu, 9 Jan 2003, Suresh Addagalla wrote:
> Date: Thu, 9 Jan 2003 12:18:10 +0530
> From: Suresh Addagalla <su...@wipro.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
> suresh.addagalla@wipro.com
> To: struts-user@jakarta.apache.org
> Subject: Application scope variables
>
> Hi,
>
> I have a few options for storing application level data, and need your
> opinions on deciding on a strategy.
>
> My requirement is to load a couple of properties files in the
> application startup and to be able to access them across all classes and
> JSPs in the web application.
>
> 1. Using the ServletContext of ActionServlet
> 2. Using the pageContext of JSP (PageContext.APPLICATION_SCOPE)
These two are identical. Anything you set through one is visible through
the other.
> 3. Using JSTL <c:set> tag (Does Struts provide a similar tag?)
The closest analog is <bean:define>. But this is not really an
appropriate use of JSP pages in an MVC architecture.
> 4. Any other..
>
> If I use 2 or 3, will I able able to access a property in, say, the
> execute method of an Action class? What's the best way to do this?
>
My recommendation is to set up shared stuff like this as servlet context
attributes, either in a PlugIn (Struts 1.1) or a ServletContextListener
(Servlet 2.3). Anything stored as servlet context attributes is instantly
available as application scope beans in a JSP page, through standard JSP
tags, through PageContext.APPLICATION_SCOPE, or any other way you want to
do it.
> Thanks,
> Suresh
>
Craig
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>