Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bean cannot be found in any scope

 
utkarsh sinha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Past few days i am trying to run my application bt it give the following error bean cannot be found in any scope.I have declared the bean in struts-config.xml.Please help.I am Pasting relevant peices of my code::

Struts-config.xml

<form-beans>
<form-bean name="TwoForm" type="TwoForm"/>
<form-bean name="loginForm" type="LoginForm"/>

</form-beans>
<global-exceptions/>
<global-forwards>
<forward name="login" path="/login.jsp"/>
</global-forwards>
<action-mappings>
<action input="/login.jsp" name="loginForm" path="/Login"
scope="session" type="LoginAction" validate="true">
<forward name="success" path="/employeelist.jsp"/>
</action>
<action input="/employeelist.jsp" name="twoForm" path="/Two"
scope="request" type="TwoAction">
<forward name="success" path="/report1.jsp"/>
</action>
</action-mappings>

TwoForm.java

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
@SuppressWarnings("serial")
public class TwoForm extends ActionForm {

private String Reqid;
private String Acti;
private String startdate;
private String hours;
private String minutes;
private String comments;
private List TwList;
private String step;
public TwoForm() {
Acti = "";
Reqid = "";
startdate="";
hours="";
minutes="";
comments="";
}
public String getReqid() {
return Reqid;
}
public void setReqid(String Reqid) {
this.Reqid = Reqid;
}
public String getActi() {
return Acti;
}

public void setActi(String Acti) {
this.Acti = Acti;
}
public void reset(ActionMapping mapping,
HttpServletRequest request) {
this.Reqid = "";
this.Acti = "";
}
public String getStartdate() {
return startdate;
}
public void setStartdate(String startdate) {
this.startdate = startdate;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public String getHours() {
return hours;
}
public void setHours(String hours) {
this.hours = hours;
}
public String getMinutes() {
return minutes;
}
public void setMinutes(String minutes) {
this.minutes = minutes;
}
public String getStep() {
return step;
}

public void setStep(String string) {
step = string;
}
@SuppressWarnings("unchecked")
public void settwoFormObj(int index, Two empObj) {
TwList.set(index, empObj);
}

@SuppressWarnings("unchecked")



public List getTwList() {
return TwList;
}

public void setTwList(List TwList) {
this.TwList = TwList;
}
@SuppressWarnings("unchecked")
public Two getTwo(int index)
{
// make sure that cusList is not null
if(this.TwList == null)
{
this.TwList = new ArrayList();
}

// indexes do not come in cus, populate empty spots
while(index >= this.TwList.size())
{
this.TwList.add(new Two());
}

// return the requested item
return (Two) TwList.get(index);

}

}

TwoAction.java

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
@SuppressWarnings("serial")
public class TwoForm extends ActionForm {

private String Reqid;
private String Acti;
private String startdate;
private String hours;
private String minutes;
private String comments;
private List TwList;
private String step;
public TwoForm() {
Acti = "";
Reqid = "";
startdate="";
hours="";
minutes="";
comments="";
}
public String getReqid() {
return Reqid;
}
public void setReqid(String Reqid) {
this.Reqid = Reqid;
}
public String getActi() {
return Acti;
}

public void setActi(String Acti) {
this.Acti = Acti;
}
public void reset(ActionMapping mapping,
HttpServletRequest request) {
this.Reqid = "";
this.Acti = "";
}
public String getStartdate() {
return startdate;
}
public void setStartdate(String startdate) {
this.startdate = startdate;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public String getHours() {
return hours;
}
public void setHours(String hours) {
this.hours = hours;
}
public String getMinutes() {
return minutes;
}
public void setMinutes(String minutes) {
this.minutes = minutes;
}
public String getStep() {
return step;
}

public void setStep(String string) {
step = string;
}
@SuppressWarnings("unchecked")
public void settwoFormObj(int index, Two empObj) {
TwList.set(index, empObj);
}

@SuppressWarnings("unchecked")



public List getTwList() {
return TwList;
}

public void setTwList(List TwList) {
this.TwList = TwList;
}
@SuppressWarnings("unchecked")
public Two getTwo(int index)
{
// make sure that cusList is not null
if(this.TwList == null)
{
this.TwList = new ArrayList();
}

// indexes do not come in cus, populate empty spots
while(index >= this.TwList.size())
{
this.TwList.add(new Two());
}

// return the requested item
return (Two) TwList.get(index);

}

}

Two.java


public class Two {

private String Reqid;
private String Acti;
private String startdate;
private String hours;
private String minutes;
private String comments;

public String getReqid() {
return Reqid;
}
public void setReqid(String Reqid) {
this.Reqid = Reqid;
}
public String getActi() {
return Acti;
}
public void setActi(String Acti) {
this.Acti = Acti;
}
public String getStartdate() {
return startdate;
}
public void setStartdate(String startdate) {
this.startdate = startdate;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public String getHours() {
return hours;
}
public void setHours(String hours) {
this.hours = hours;
}
public String getMinutes() {
return minutes;
}
public void setMinutes(String minutes) {
this.minutes = minutes;
}
}

The most imp jsp page which displays the result(report1.jsp)

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html xhtml="true">

<head>
<title><bean:message key="app.title" /></title>
<html:base/>

</head>

<body>
<h2>HIIII

<bean:write name="TwoForm" property="Acti" />
<bean:write name="TwoForm" property="Reqid" />
<bean:write name="TwoForm" property="hours" />
<bean:write name="TwoForm" property="minutes" />
<bean:write name="TwoForm" property="comments" />
<bean:write name="TwoForm" property="startdate" />
</h2>

<h3><bean:message key="app.title" /></h3>


<table border=1>
<tr><th>Activity<th>ReqNo</th><th>Hours</th><th>Minutes</th><th>Comments</th><th>Date</th></tr>

<logic:iterate id="Two" name="TwoForm" property="TwList">
<tr><td>
<bean:write name="Two" property="Acti"/></td>

<td><bean:write name="Two" property="Reqid"/></td>
<td><bean:write name="Two" property="hours"/></td>
<td><bean:write name="Two" property="minutes"/></td>
<td><bean:write name="Two" property="comments"/></td>
<td><bean:write name="Two" property="startdate"/></td>

</logic:iterate>
</table>




</body>

</html:html>
Error Which i am receiving is as follows:

javax.servlet.jsp.JspException: Cannot find bean TwoForm in any scope
org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:938)
org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:286)
org.apache.jsp.report1_jsp._jspx_meth_bean_write_0(report1_jsp.java:272)
org.apache.jsp.report1_jsp._jspService(report1_jsp.java:101)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts is generally case sensitive (and since Java is also, Struts pretty much has to be case sensitive). I notice that in your form bean definition you use "TwoForm" and in your action mapping you use "twoForm". I would adopt a convention and stick with it.

It looks like you mistakenly posted the code for TwoForm.java a second time instead of posting the code for TwoAction.java.

- Brent
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic