Apparently, the preceding answers seem wrong. Here is what says the JSP 2.0 specification:
The jsp:useBean action is quite flexible; its exact semantics depends on the attributes given. The basic semantic tries to find an existing object using id and scope. If the object is not found it will attempt to create the object using the other attributes.
And in the Tomcat 5.0.30 source code (org/apache/jasper/compiler/Generator.java), I found that Tomcat uses the JspContext.getAttribute(String name, int scope) and not the JspContext.findAttribute(String name). And if the scope attribute is not given by the developper, the "page" scope is used by default.
So the scope tag attribute is well used when retrieving the bean.
Rohit, maybe you should check an error somewhere else:
- Check if the name attribute of foo.mybean is not declared as static
- Check that you have no typo in your real code (the one you pasted in your question is right)
- Check that your server isn't using another version of your code (bad web-app location, outdated cache, ...)
Apart from this, I cannot imagine what has gone wrong.
I hope these informations will help you.