aspose file tools
The moose likes Struts and the fly likes Cannot find bean  in any scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Cannot find bean  in any scope" Watch "Cannot find bean  in any scope" New topic

Cannot find bean in any scope

Raf Beni

Joined: Aug 22, 2011
Posts: 4
Hi everybody!

I try to do a web with structs! and now i have this problem:

*This is my struct ActionForm bean
public class StudentForm extends org.apache.struts.action.ActionForm {

private List<Student> stuList;
private String rollNoParamInForm ;

public String getRollNoParamInForm() {
return rollNoParamInForm;

public void setRollNoParamInForm(String rollNoParamInForm) {
this.rollNoParamInForm = rollNoParamInForm;

public List<Student> getStuList() {
return stuList;

public void setStuList(List<Student> stuList) {
this.stuList = stuList;


*and my struct Action:
public class InitDataAction extends org.apache.struts.action.Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

Connection con = DBUtility.getConnection();
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = con.prepareStatement("select * from Student");
rs = stm.executeQuery();
List<Student> list = new ArrayList<Student>();
while ( {
Student stu = new Student();



java.util.Date dob= new Date(rs.getDate("dob").getTime());
SimpleDateFormat dateFormat= new SimpleDateFormat("dd/MM/yyyy");

StudentForm stuForm= (StudentForm) form;
} finally {

return mapping.findForward("initOk");

*my jsp to display data :StudentList.jsp
<%@ 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" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<h1 style="background-color: gray">Student List</h1>
<table border="1">
<logic:iterate name="StudentForm" property="stuList" id="student">
<td><bean:write name="student" property="name" /></td>
<td><bean:write name="student" property="className" /></td>
<td><bean:write name="student" property="dob" /></td>
<td><bean:write name="student" property="gioiTinh" /></td>
<logic:equal name="student" property="sex"value="true" >Male</logic:equal>
<logic:equal name="student" property="sex"value="false" >Female</logic:equal>
<html:link action="PrepareDataForUpdate" paramId="rollNoParamInForm" paramName="student" paramProperty="rollNo">
<bean:write name="student" property="rollNo" />
<span style="background: gray"><html:link action="AddNew">Add new</html:link></span>
<span style="background: gray"><html:link action="BackToHome">Back to home</html:link></span>

<action input="/" name="StudentForm" path="/InitDataAction" scope="session" type="abc.InitDataAction">
<forward name="initOk" path="/StudentList.jsp"></forward>

And when run proejct. error:
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "StudentForm" in any scope

Do you have me to solve it??
Orton K Randy
Ranch Hand

Joined: Aug 12, 2011
Posts: 41

Please UseCodeTags.

Is the action class run before you call the JSP? Otherwise, you don't have a StudentForm with you in any scope, let alone session. That is, InitDataAction must be performed before you route to the JSP like you mentioned in the struts-config.xml. If you tried to access the JSP directly in anyway(before the InitDataAction is invoked), you're likely to get this error. What URL do you hit to run the app?

Coderanch, best ever forum on the net. Hands down.
Raf Beni

Joined: Aug 22, 2011
Posts: 4
Dear Orton K Randy
Sorry, I will use code tag for next time!

How to run action class?? after i create project, i have page "index.jsp " and i write in index.jsp
when i run project, its url is: "http://localhost:8081/NameProject/" and it error "The requested resource (/NameProject/InitDataAction) is not available."
manikandan jayakumar
Ranch Hand

Joined: Aug 20, 2011
Posts: 44

In the above code type represents the InitDataAction.class file under abc.
Orton K Randy
Ranch Hand

Joined: Aug 12, 2011
Posts: 41

I'll make it clear, you don't run the Action class yourself, rather you perform the action that would invoke the action class. So, you should have run it as:
or if you intend to use a JSP(index.jsp in your case) to perform the InitAction, here's how you do it.


In your struts-config.xml(after </form-beans>),
Raf Beni

Joined: Aug 22, 2011
Posts: 4
Ok! I solved it!
I used a html link and call action to the InitDataAction, and data was be showed!

Thanks for help
I agree. Here's the link:
subject: Cannot find bean in any scope