wood burning stoves 2.0*
The moose likes JSP and the fly likes MVC2.0 how to pass bean object to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "MVC2.0 how to pass bean object to jsp" Watch "MVC2.0 how to pass bean object to jsp" New topic
Author

MVC2.0 how to pass bean object to jsp

harish pathak
Ranch Hand

Joined: Dec 17, 2005
Posts: 51
Hi All,

Anybody please tell me how to pass bean class object from controller to jsp ?

I am developing an application in MVC2.0.
I am creating an object of bean class in controller servlet and want to pass this object to jsp so anybody please tell how to pass this object to jsp.

-----------------------------
ControllerServlet--

Bean obj = new Bean();
-----------------------------
Bean --

public String aMethod() {

return data;
}

--------------------
I have to use this method in my jsp and I am creating an object of this bean in controller servlet.

Please help

Thanks

Please reply soon
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you follow the javabean conventions for naming accessors and mutators (setters and getters) and give them names that start with get, set, or is, you can access your bean properties with either the <jsp:getProperty ../> tags or with the newer EL expression tags ${beanName.firstName}.
If you don't follow those conventions, you will need to resort to scriptlet expression tags <%=beanName.getFirstName()%>.

In any case, the way to share beans between servlets and JSPs is to bind them to one of the scope objects (request, session, context) with the get/setAttribute methods.

See
java.lang.String,%20java.lang.Object&#41;" target="_blank" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletRequest.html#setAttribute(java.lang.String,%20java.lang.Object)
java.lang.String&#41;" target="_blank" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSession.html#getAttribute(java.lang.String)
java.lang.String&#41;" target="_blank" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getAttribute(java.lang.String)

If you aren't using JSP2.0 you should also read up on the <jsp:useBean .. /> tag which provides a very easy way to access session scoped beans from your JSPs.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
Consider Paul's rocket mass heater.
 
subject: MVC2.0 how to pass bean object to jsp
 
Similar Threads
Struggling With Passing Data Between Data Access Class, Business Bean, and Controller
how can I pass an Object or String from Applet to JSP?
Spring - MultiActionController with multiple buttons
Login application in MVC2.0 ..
How to pass a class object from servlet to jsp page