• Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaBean scope  RSS feed

 
kang chen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have some question regarding the scope of JavaBean.
I used JavanBean in 2 JSP page. They worked fine in Tomcat.
But I got error message ( "myBean" is not a defined bean variable on this page)when I running them in Weblogic.
I need to put "<jsp:useBean id="myBean" scope="request" class="javabean.Counter"/>" in Hello.jsp to fix it.
Can anyone explain it for me?

The following code is these 2 JSP page.

_________________________________________________________________________
1. p1.jsp:
<%@ page language="java" contentType="text/html %>
<html>
<head>
<title>JavaBean - request</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<jsp:useBean id="myBean" scope="request" class="javabean.Counter"/>
<p>You have visited<font color="red">
<jsp:getProperty name="myBean" property="count"/>
</font>times</p>

<jsp:include page="Hello.jsp" flush="true"/>
</body>
</html>

2. Hello.jsp
<%@ page language="java" contentType="text/html;charset=Big5" %>
Hello ...

Thank your visit for the<font color="red"><jsp:getProperty name="myBean" property="count"/> times</font>

___________________________________________________________________________
Thanks in Advanced
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should not work. You need a jsp:userBean delcaration in each page thet will reference the bean. And, since you delcared the scope as request, each page will have its own copy of the bean.
 
kang chen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your information. But it does not need to use jsp:userBean delcaration in each page for the scopes of request, session and application. I have used the same code and it running fine in Tomcat.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!