• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

jsp:useBean problem

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friends

I am using Tomcat 5.

In servlet I wrote the following code

public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
foo.mybean mb=new foo.mybean();
mb.setName("Universe");

foo.mybean mb1=new foo.mybean();
mb1.setName("World");

request.setAttribute("obj",mb1);
request.getSession().setAttribute("obj",mb);

request.getRequestDispatcher("/useBean.jsp").forward(request,response);
return;
}

Now in useBean.jsp I wrote the following code

<jsp:useBean id="obj" class="foo.mybean" scope="session"/>
<jsp:getProperty name="obj" property="name"/>

In foo.myBean I have just a getter and setter method for setting and getting the name..

Now I was expecting to get the output "Universe" but was shocked to see that I was getting "World" as output despite of me setting the scope to "session" in <jsp:useBean> tag !!

Is this a bug in Tomcat 5 or I am misunderstood ?

Please help me ..
Waiting for your replies..

Thanks and Regards
Rohit
[ February 25, 2005: Message edited by: Bear Bibeault ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should look at the Java code that the Jasper compiler turned your JSP page into for the answer. I think that will be found under the work directory.
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<jsp:useBean id="obj" class="foo.mybean" scope="session">
<jsp:getProperty name="obj" property="name"/>
</jsp:useBean>

The above code will not work as the object obj already exists in session and if the obj exists in the scope specified then the code inside the useBean never executes..So this will not help

I saw the code in the work directory and there I saw that tomcat is using the method findAttribute() for finding the attribute and since findAttribute goes on finding the obj from page scope to application scope thats why it gets the object from request so it doesnt search in session scope which is one level above request scope..

Thats y I said I think it is tomcat 5 bug !!

Waiting for your reply
Thanks and Regards
Rohit.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can find a statement in the Servlet/JSP specifications that says that the session scope should be searched before page scope then you have found a bug. Otherwise not - since Tomcat is the reference implementation of the specification, I doubt you will find that statement.
http://java.sun.com/products/servlet/reference/api/index.html
Bill
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
If you can find a statement in the Servlet/JSP specifications that says that the session scope should be searched before page scope then you have found a bug.



I can't find anything about "searching the various scopes" for an object. Everything I'm reading indicates that the object will be looked for in the scope specified in the "scope" attribute.

Rohit,
I ran this code in 5.0.28 and I'm seeing the same behaviour that you described. I'm going to try in a more recent version and continue reading the spec.

William,
If you can point out a section in the JSP spec that clears this up, I would be most grateful.

-Ben
[ February 26, 2005: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And...
this thread should be in the Tomcat forum.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to use type instead of class in jsp:useBean.
 
reply
    Bookmark Topic Watch Topic
  • New Topic