How to pass a java object to jsp page

user525146 picture user525146 · Mar 13, 2012 · Viewed 22.4k times · Source

I have a serveresource method which is invoked on clicking a link. The serveresource method takes the input from the parameter that was passed and retrieves a row from the database. Now all the values in a row are in set using the mutator methods. I have everything in a java object. I need to pass this object to a jsp page to print the values of a single row on the jsp page. I am not sure how to handle that java object in the jsp page instead of setting each value as an attribute in the serveresource method. Need help from experts.. Thanks in Advance

UPDATE

It was because I have an Ajax call and when I set values it is in a completely different life cycle which is causing the problem. I figured it out.

Answer

Ramesh PVK picture Ramesh PVK · Mar 13, 2012

You should defining the java object as Bean in JSP. The Bean in JSP can be defined using < jsp:useBean..> standard jsp tag. And set and get property using < jsp:setProperty..> and < jsp:getProperty..> standard jsp tags.

Refernces: