• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scope of the object

 
giridhar k
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
this is what given in the JSP specs.
"the object should have been present in the session. If so,
it is given the local name wombat with WombatType. A ClassCastException
may be raised if the object is of the wrong class, and an
InstantiationException
may be raised if the object is not defined."
<jsp:useBean id=wombat type=my.WombatType scope=session/>

I tried to work it out using the following example.
*******************************************
**********Interface Sup***************
interface Sup
{
public String getVer();
}

****************Class SysProp***************
public class SysProp implements Sup
{
String ver="Hello";
public String getVer()
{
return ver;
}

public void setVer(String v)
{
ver=v;
}
public static void main(String []ar)
{
System.out.println(new SysProp().getVer());
}
}

******************SysProp.jsp*****************
<jsp:useBean id="props" class="SysProp" scope="session"/>
<html>
<head><title>Miscellaneous System Properties</title></head>
<body>
<form action="test.jsp">
<jsp:setProperty name="props" property="ver" value="hi"/>
OS version:
<jsp:getProperty name="props" property="ver" />
<input type="submit" >
</form>
</body>
</html>
***************test.jsp**********************
<jsp:useBean id="pr" type="Sup" scope="session"/>
<html>
<head><title>Miscellaneous System Properties</title></head>
<body>
OS version:
<jsp:getProperty name="pr" property="ver" />
</body>
</html>
*********************************************
If i run this code SysProp.jsp is running perfectly fine. But After submitting the "SysProp.jsp" the following exception is thrown

**************************************************
28/Aug/2002:12:23:11] failure ( 1772): Internal error: exception
thrown from the servlet service function (uri=/test.jsp):
javax.servlet.ServletException: bean pr not found within scope , Stack:
javax.servlet.ServletException: bean pr not found within scope
at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:384)
at
_0005ctest_0002ejsptest_jsp_0._jspService(_0005ctest_0002ejsptest_jsp_0.java:87)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:826)
at
com.netscape.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:462)




as attachmentinline text

*********************************************

Pls provide if u have any explanitation why this error has occoured
thank u
regards
giridhar
 
k space
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try changing the id="pr" in <jsp:useBean id="pr" type="Sup" scope="session"/> to id="props".
It is because SysProp object created in <jsp:useBean id="props" class="SysProp" scope="session"/> was bound to an attribute in HttpSession called "props".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic