jQuery in Action, 3rd edition
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
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

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.


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


Please reply soon
Ben Souther

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.

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
I agree. Here's the link: http://aspose.com/file-tools
subject: MVC2.0 how to pass bean object to jsp
It's not a secret anymore!