ServletException: bean not found within scope

HI All,

My app running in Jboss, when I try to click on the menu option. I'm getting following error:

javax.servlet.ServletException: bean descriptionVO not found within scope

at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)

at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)

at org.apache.jsp.AddRigMapping_jsp._jspService(AddRigMapping_jsp.java:305)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

.................

and my jsp is

<%@ taglib prefix="c" uri="Standard" %>

<%@ taglib prefix="x" uri="Custom" %>

<html>

<head>

<meta http-equiv="Content-Language" content="en-gb">

<meta http-equiv="Content-Type" content="text/html;CHARSET=iso-8859-1">

<title>Add RigMapping</title>

<link rel="stylesheet" type="text/css" href="styles/pageStyle.css">

<%@ page import="zaa.co.rmba.di.util.Constants" %>

<jsp:useBean id="addlistVO"type="zaa.co.rmba.di.beans.AddListVO"scope="session" />

<SCRIPT LANGUAGE="JavaScript" SRC="javascript/util.js"></SCRIPT>

<SCRIPT LANGUAGE="JavaScript" SRC="javascript/date/AnchorPosition.js"></SCRIPT>

<SCRIPT LANGUAGE="JavaScript" SRC="javascript/date/PopupWindow.js"></SCRIPT>

<SCRIPT LANGUAGE="JavaScript" SRC="javascript/date/CalendarPopup.js"></SCRIPT>

<SCRIPT LANGUAGE="JavaScript" SRC="javascript/date/Date.js"></SCRIPT>

<SCRIPT LANGUAGE="JavaScript" SRC="javascript/util.js"></SCRIPT>

<jsp:useBean id="descriptionVO" type="zaa.co.rmba.di.beans.DescriptionVO" scope="session" />

<jsp:useBean id="confirmationVO" type="zaa.co.rmba.di.beans.ConfirmationVO" scope="session" />

<jsp:useBean id="dateVO" type="zaa.co.rmba.di.beans.DateVO" scope="request" />

<%@ include file="menu.html" %>

</head>

<body>

<hr>

<h3>Add RigMapping</h3>

<form name="AddRigMapForm" method="POST" action="FrontController?command=AddRigMapping">

<div class="tdc">

<center>

<table border="0" width="697">

...................................

and my bean is

package zaa.co.rmba.di.beans;

public class DescriptionVO {

private String reportcodeDescription;

private String majorcodeDescription;

private String subcodeDescription;

........................................

}

Any body know, what causing the problem. Any help will be greatly appreciated.

thanks in advance

[2869 byte] By [saleemImran] at [2007-9-30 18:50:01]
# 1

This is caused by one of those wierd hidden behaviors of jsp:useBean. When you do:

<jsp:useBean id="..." type="..." scope="..."/>

then jsp:useBean will look for a bean of that type inside the scope provided, but will not make a new one if it is not found.

This is because 'type' is used to represent the run-time type of the object, which is not always the class of the object (for instance, If I do List list = new ArrayList(), the type of the object is java.util.List, while the class is java.util.ArrayList).

Since the type does not have to be an instatiable class (ie, it could be an Abstract Class or an Interface as in the List example) jsp:useBean will not try to make one.

To get around this, you would use the 'class' attribute for jsp:useBean if you want to force the bean to be created when this line is first approached:

<jsp:useBean id="descriptionVO" class="zaa.co.rmba.di.beans.DescriptionVO" scope="session" />

By providing the 'class' rather than the 'type,' you are assuring jsp:useBean that the object can be instantiated (that descriptionVO = new zaa.co.rmba.di.beans.DescriptionVO(); is possible)

stevejluke at 2007-7-6 21:07:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks...you explain nicely..thanks again. It's working
saleemImran at 2007-7-6 21:07:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Same problem I have faced. But my difficulty is that I have to specify the "type" attribute and not the "class" attribute. Since if i mention the class name as the value to "class" attribute, it tries to find the object and if not foound it creates a new instance of that bean. But actually I am setting the value in the bean inside a servlet and then setting it into the request. Then in the JSP, I am trying to retreive the bean using useBean tag. But it is giving me exception "Bean not found exception".

May I know that what could be the reason for this?

my_java_screen at 2007-7-6 21:07:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...