Hello, everyone,
I want to share a bean instance data across pages.
I create two
jsp pages, one is setUserInfo.jsp, to set the bean property, another is getUserInfo.jsp to get bean peroerty. I set a link in the setUserInfo.jsp, to refer to the getUserInfo.jsp.
However, I can not see the propery value in the getUserInfor.jsp page. I thought scope attribute might determine the visibility range of the bean, In both jsp pages, I set scope attribute to "session" and "applicaiton" , but neither works.
Could you tell what I am wrong?
Folloing is the my code and jsp. Thanks,
1. setUserInfor.jsp
********************************************************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
Java Session Bean Example</TITLE>
</HEAD>
<BODY>
<jsp:useBean id="user" class="moreservlets.User" scope="application" />
<jsp:setProperty
name="user"
property="name"
value="martin" />
<jsp:setProperty
name="user"
property="addr"
value="2442 7ave NW" />
This jsp page is feeding the java session bean user with the following info.
<br>
name: martin
<br>
addr: 2442 7ave nw
<br>
<a href="getUserInfo.jsp">
click to </a> go to the getUserInfo.jsp for user information
</p>
</BODY>
</HTML>
***********************************************************************
2. getUserInfor.jsp
***********************************************************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Java Session Bean Example</TITLE>
</HEAD>
<BODY>
<jsp:useBean id="user" class="moreservlets.User" scope="application" />
User Information:
<br>
name: <jsp:getProperty name="user" property="name" />
<br>
addr: <jsp:getProperty name="user" property="addr" />
</BODY>
</HTML>
**********************************************************************
3.User.java
**********************************************************************
package moreservlets;
public class User {
private
String name;
private String addr;
public void setName(String name) {
name=this.name;
}
public String getName() {
return name;
}
public void setAddr(String addr) {
addr=this.addr;
}
public String getAddr() {
return addr;
}
}
************************************************************************