Amithkumar:
The following is my observation:
1. If you don't specify the scope attribute in <jsp:useBean..>, then the scope defaults to "page". (Ref: HFSJ top of page 355).
So, in the situation where you don't have a scope attribute with
<jsp:useBean id="person" type="foo.person"/>
the scope defaults to page, and the statement is same as having:
<jsp:useBean id="person" type="foo.person" scope="page"/>
In summary, it will not search or find in any other scope (unlike an EL attribute where it will search in all four scopes).
You can try this with the following example:
<%@ page import="foo.*" %>
<html>
<body>
<%
person lclperson = new foo.person();
lclperson.setName("YourName");
pageContext.getSession().setAttribute("person", lclperson);
// pageContext.setAttribute("person", lclperson);
%>
<br>
<jsp:useBean id="person" type="foo.person" />
<jsp:setProperty name="person" property="name" value="SomeName" />
<jsp:getProperty name="person" property="name"/>
<br>
Done.
</body>
</html>
The
java bean:
package foo;
public class person {
private
String name = null;
public person() {
name = "";
}
public String getName() {
return name;
}
public void setName(String inname) {
name = inname;
}
}
2. For the second question, your observation is the same as mine, that is it does print "Second Page" - this only if I ignore the following syntax error in your post:
<jsp:getProperty name="bean" property="name">
is not properly terminated, if above line is used as is, you will get compile error.
Hope this helps.
Narendra:
What is the meaning of your reply above? I did not get it. "It will not search in all scope." is correct. However, the next sentance you mention "class/beanName" - what has this got to do with scope - I don't think scope depends on these attributes in anyway. Also, what did you mean by "given scope"? May be you ment the default scope - "page"...