Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

Setting Application object only one

I am involved in colloborative product developement. I set a value in an application oject during login. Since this is a colloborative product, there will me multiple logins at the same time. For each user login a seperate application object is set. How to avoid this?
0
Delphine_victorus
Asked:
Delphine_victorus
1 Solution
 
TimYatesCommented:
static ApplicationObject login ;

or something

static means you only get one instance for all instances of the class
0
 
shji1Commented:
You can use a singleton design pattern in order to assign the same application object instance to all of the logins.

In general, a singleton is written in this way:

private static SomeObject o;

public static SomeObject getInstance() {
    if (o == null) {
        o = new SomeObject();
    }
    return o;
}

Every time you want to get an instance of SomeObject you should call the getInstance.

0
 
Delphine_victorusAuthor Commented:
Thanks for immediate reply from both of you.

I set the value in application object this way in the login page -

application.setAttribute("AttributeName", attributeValue);

and I read it whereever necessary this way -

application.getAttribute("AttributeName");

How do I use your suggestions in my code?
   
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Delphine_victorusAuthor Commented:
Thanks for immediate reply from both of you.

I set the value in application object this way in the login page -

application.setAttribute("AttributeName", attributeValue);

and I read it whereever necessary this way -

application.getAttribute("AttributeName");

How do I use your suggestions in my code?
   
0
 
karlikaCommented:
Try this:

static Hashtable table = new Hashtable();

public void setAttribute("AttributeName", attributeValue){
  table.put("AttributeName", attributeValue);
}

public Object getAttribute("AttributeName"){
  return table.get("AttributeName");
}
0
 
rrzCommented:
I am assuming you are talking about JSP.
Use a bean and the container will do what you want done.
Put the tag on each page/.
<jsp:useBean class="yourclass" id="login" scope="application" />
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now