Skip to main content

Storing objects for use in whole web app

1 reply [Last post]
Joined: 2009-06-21

Hi all,

Hopefully the correct forum section. Firstly I would like to say that I am a student still learning Java but more in desktop developing terms. I have been trying to get into doing some web app development to get some experience on how it works etc.

To the problem... Please give me a good virtual slap if this makes no sense.

I am trying to write a simple web app using the MVC style but without any large frameworks such as spring, faces, etc to start. So basically Source -> Servlet -> JSP

What I would like to know is how best to store objects or even if storing them is the correct way in the web app. I will be using Glassfish.

Say I am trying to create a simple web login page that takes user input then checks a database for matching info. If found it creates a new user object like User myUser = new User() where should this object be stored for later use accessing secure pages. Any best practices?

Should the object be stored in a session, application context, or a controlling class. Or should I drop the object and just store basic information such as Strings in the session. I am trying to avoid using a database to store an object.

A controlling class sounds similar to the desktop style but seems a little different in implementation. (storing user objects in a collection)

Also if this information helps, I am not using a "god" servlet or a servlet per page. More along the lines a servlet per category so one for the entire authentication area of things and another for other parts of the web app.

- ptkee

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-06-21