Can you bring more context to model Attribute and session Attribute? Where do you see these things, are they in a framework or are you talking Java EE? Those terms can be rather generic, so providing more details about where you see them may provide more better answers.
posted 8 years ago
Thank you Steve.
I will explain the context. We have designed an application where you can book the flight Tickets and our application has two kinds of Users- Online user and Marketing User(this user has a login Id and password with which he can login into the application. Something like an Admin user.)
So for using some variables across all the pages , we are putting some variables like language code, region name etc in session .
And also , we are setting some variables in model also like this .
What I need to know is , what is the difference between storing in a session and adding it in a model ?
Why should I use both ? Is there any relationship between setting in a session and setting in a model? Or is both settings are different?
That is still awfully sparse on details. I will assume you are creating a web application.
A session is generally a context shared by a single user across multiple pages in a web application. I have no clue what your model object is, it is not a generic Java object, so I can't tell you what it does or how it might be different than the session. Generally speaking, in an MVC framework, the Model manages behavior and data. Conceptually I think of the session as part of the Model layer in an MVC application. In your case I would believe that the model object probably provides more application specific storage, maybe provides a chance for your application to react to the data you store in it, and might provide a bridge between the View (web part) of the application and the rest of the Model (business logic) part of the application. If this is true, then the session would be used to store View & Control parts of the application data (those parts required to properly display pages, control page / view flow) and the model object would be used to store application specific business related data (ticketing information, fare and seat data, database configs...).
To figure out how the two objects are different you should research about what type the model object is, where it is created, where it gets stored, and where it gets used. To learn more about the session object, any JavaEE tutorial or book will do.