Hi everybody, I am Chaitanya, I am getting confused whether to use a Bean or a Map.
My aim is to select user profile data from database. For this I used MVC. In model, should I use a Bean and set all the profile data or should I create a Map and return the Map to controller and the add the Map to response object and print the details in jsp.
If you use a Map, you can put anything in it. But you don't have a clear view of what the model is. All you see is : Map<String, Object> myModel. What's in it ? You don't know. until you loop through it. If you use a bean, you clearly see which properties it has, which relations it has with other beans... You clearly see that a Person has a first name, a last name... With a Map, you don't.
Nowadays, beans used as the model are closely related to database entities. They are used to persist your data into a database. You may have a Person bean which is related to a Person table, a Company bean which has its properties stored in a Company table... Using a map for everything is not going to help you do that easily. If you start playing with JPA or persistence containers like Hibernate, you'll see that using a separate class is a must.
A part from that, from a design point of view, as I said earlier, a Map hides everything. Imagine that someone of your team is making a few JSP to add/update/delete/list some of your model. How will he know which properties your model is holding if you are using a Map. A Map is fine for playing alone But not maintainable.
The use will click on a link named viewProfile. An appropriate servlet is called. Then that servlet sends the user_id to the model. The model selects the details from database and creates a person bean, then the controller adds the bean to response and calls user_details.jsp.