0

in asp there's an Application object, which is like the Session but it's shared among all sessions...

http://msdn.microsoft.com/en-us/library/ms525360.aspx

You can use the Application object to share information among all users of a given application. An ASP-based application is defined as all the .asp files in a virtual directory and its subdirectories. Because the Application object can be shared by more than one user, there are Lock and Unlock methods to ensure that multiple users do not try to alter a property simultaneously.

I use this object to implement a simple cache for small sets of data...

What is java / jsp equivalent?

thanks a lot...

3 Answers 3

1

ServletContext is similar to the ApplicationObject. You can use the setAttribute method to add information shared by all users. From within a servlet, you can call getServletContext() to gain access to it. I am not sure however if it provides locking/unlocking functionality.

If you are using Spring or another IoC container, you can easily define a bean that is accessible from all users. I suppose this is a better solution for both worlds.

Sign up to request clarification or add additional context in comments.

Comments

1

Application scope in JSP is identical to ServletContext.

Comments

0

I know of two ways to accomplish this in JSP.

  1. Define a bean in the application scope:

    <jsp:useBean id="appCounter" class="com.company.AppCounter" scope="application" />

  2. Create a singleton class. Example

3 Comments

Singletons should be avoided in JEE containers.
I don't think that singletons should be avoided, but used carefully. Obviously the better choice here is to use the servlet context. Also, in the future please give an explanation when you make statements like that.
Read code.google.com/p/google-singleton-detector and artima.com/weblogs/viewpost.jsp?thread=213214. This is not so easy to explain in an answer or a comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.