Best practice ? send Object to request or desired pieces of data?

Newbie to this style of programming...

Is the best practice to put the customer object in the session or request object and allow jsp's to declare and instantiate the customer object out of the session/request (then use whatever getters are needed to properly display the desired data)?

Or would it be better to send the customer ID, Name, address etc as a string to the session/request object and just have the JSP declare the strings & instantiate from the session/request object(thus keeping more complicated java code out of the jsp)?

Thanks for the help in advance!

[600 byte] By [Perryiera] at [2007-11-27 11:12:48]
# 1

The best practice is to avoide code in jsp pages so, I usually send the objects in session/request.

manuel.leiriaa at 2007-7-29 13:56:57 > top of Java-index,Java Essentials,Java Programming...
# 2

Doesn't this result in more code? If we send the object, we need code to declare and instantiate the object, then use the getters to get the data to display.

If I just send the necessary data, I just need to declare a string = request.getParameter... or just display the request.getParameter.

I actually like the concept of sending the object, it seems cleaner and less likely to result in servlet changes down the road, but i want to make sure there is not some other reason NOT to do this.

Perryiera at 2007-7-29 13:56:57 > top of Java-index,Java Essentials,Java Programming...
# 3

> I actually like the concept of sending the object, it seems cleaner

It is cleaner. JSTL can make things even tidier, providing tag-based access to object properties. Example:

<c:out value="${myObject.someProperty}" />

~

yawmarka at 2007-7-29 13:56:57 > top of Java-index,Java Essentials,Java Programming...