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??