?
Solved

Setting Application object only one

Posted on 2003-03-06
6
Medium Priority
?
152 Views
Last Modified: 2010-03-31
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
Comment
Question by:Delphine_victorus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 8081590
static ApplicationObject login ;

or something

static means you only get one instance for all instances of the class
0
 
LVL 1

Expert Comment

by:shji1
ID: 8081721
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
 

Author Comment

by:Delphine_victorus
ID: 8081824
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Delphine_victorus
ID: 8081843
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
 
LVL 2

Expert Comment

by:karlika
ID: 8082179
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
 
LVL 28

Accepted Solution

by:
rrz earned 60 total points
ID: 8083948
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question