TechnoBuzz

A Techno Blog, mainly about Java

The Application scope

getting an object that was placed in application scope (done in Struts Action):

In your Struts Action Class (inherits from org.apache.struts.action.Action) , like was done here just create the following method:

       protected Object getApplicationObject(String attrName) {
         return servlet.getServletContext().getAttribute(attrName);
     }

setting an object into application scope can be done by implementing a struts plugin.

Create a class that extend org.apache.struts.action.PlugIn:

public class myPlugin implements org.apache.struts.action.PlugIn {

  public void init(org.apache.struts.action.ActionServlet servlet,
   ModuleConfig applicationConfig) throws ServletException {
 
     setApplicationObject(servlet, "object1", "YES");
    
    
}

protected void setApplicationObject(
   org.apache.struts.action.ActionServlet servlet, String attrName,
   Object obj) {
      ServletContext context = servlet.getServletContext();
      context.setAttribute(attrName, obj);
}
}

Don’t forget to define your plugin in struts config file:

<

plug-in className="myPath.myPlugin"/>

Lastly, remember the application scope is multithreaded

Advertisements

October 27, 2005 - Posted by | Struts

3 Comments »

  1. Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru

    Comment by Alexwebmaster | March 3, 2009 | Reply

  2. Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.

    Comment by sandrar | September 10, 2009 | Reply

  3. Sign: umsun Hello!!! rcuwwymhyw and 12ssgfhphzye and 5620I will try to recommend this post to my friends and family, cuz its really helpful.

    Comment by megan fox | September 11, 2009 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: