• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot find bean in any scope

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 {


@Override
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 (rs.next()) {
Student stu = new Student();

stu.setAge(rs.getInt("age"));
stu.setSex(rs.getBoolean("sex"));

stu.setClassName(rs.getString("className"));
stu.setName(rs.getString("sName"));
stu.setRollNo(rs.getString("rollNumber"));

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

list.add(stu);
}
StudentForm stuForm= (StudentForm) form;
stuForm.setStuList(list);
} finally {
DBUtility.closeResultSet(rs);
DBUtility.closeStatement(stm);
DBUtility.closeConnection(con);
}

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"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<center>
<h1 style="background-color: gray">Student List</h1>
<table border="1">
<tr>
<th>Name</th>
<th>Class</th>
<th>Birthday</th>
<th>GioiTinh</th>
<th>Sex</th>
<th>Edit</th>
</tr>
<logic:iterate name="StudentForm" property="stuList" id="student">
<tr>
<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>
<td>
<logic:equal name="student" property="sex"value="true" >Male</logic:equal>
<logic:equal name="student" property="sex"value="false" >Female</logic:equal>
</td>
<td>
<html:link action="PrepareDataForUpdate" paramId="rollNoParamInForm" paramName="student" paramProperty="rollNo">
<bean:write name="student" property="rollNo" />
</html:link>
</td>
</tr>
</logic:iterate>
</table>
<br/>
<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>
</center>
</body>
</html>

*struts-config.xml
<action-mappings>
<action input="/" name="StudentForm" path="/InitDataAction" scope="session" type="abc.InitDataAction">
<forward name="initOk" path="/StudentList.jsp"></forward>
</action>
</action-mappings>


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??
 
Ranch Hand
Posts: 41
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Raf Beni
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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."
 
Ranch Hand
Posts: 44
Firefox Browser VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


In the above code type represents the InitDataAction.class file under abc.
 
Orton K Randy
Ranch Hand
Posts: 41
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

http://localhost:8081/NameProject/InitAction.do

directly
or if you intend to use a JSP(index.jsp in your case) to perform the InitAction, here's how you do it.

index.jsp


In your struts-config.xml(after </form-beans>),
 
Raf Beni
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok! I solved it!
I used a html link and call action to the InitDataAction, and data was be showed!

Thanks for help
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic