I have requirement like a Java class member variables has to be accessed by 3 or more JSP files. The input to the java class will be a property file. Passing the property file to the constructor will populate the class member variables. This variables will be used by 3 or more JSP files. So instead of creating different instance with same property file, if the instance is once created and if all the JSP can access it, which will be efficient. Currently my idea is making the java class as singleton or other one is create the instance and keep it in a session and let all the jsp to access it. I feel singleton class is more appropriate. Is my decision rite or any other more efficient way is there ?
Share
I would only advice to keep objects in session which are session dependent. In this case, since you have to make the variable accessible in 3 different jsp’s and these values are not dependant on individual request, better to store the object in application context.
Use ServletContext’s getAttribute() and setAttribute() methods.Store the values in Application Scope and you should be done for good.