struts1.3获取不到jsp页面的值,求解 在struts中有form类和services类还有actions类,配置文件也写好了对应的<form-beans>和<action-mapping>,可是还是取不到值,怎么回事?小弟刚学struts。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 还在用struts1.x啊。。好老的,你这样说也没法给你找问题,至少来点代码 没办法,老师说要熟悉struts1.x,精通2.xaction代码:// 删除 public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { StudentService service = new StudentService(); StudentForm studentForm = new StudentForm(); System.out.println(studentForm.getSid()); if (service.Delete(studentForm.getSid())) { response.getWriter().print("<script>alert('" + studentForm.getSname() + "删除成功!');</script>"); return mapping.findForward("to_index"); } return null; }form代码(有get和set了)public class StudentForm extends ActionForm { private Integer sid; private String sname; private Integer ssex; private String semail;然后配置文件:<struts-config> <form-beans> <form-bean name="StudentForm" type="com.accp.forms.StudentForm"></form-bean> </form-beans> <global-exceptions /> <global-forwards /> <action-mappings> <action name="StudentForm" path="/student" type="com.accp.actions.StudentAction" parameter="op"> <forward name="to_index" path="/index.jsp"></forward> </action> </action-mappings> <message-resources parameter="com.accp.ApplicationResources" /></struts-config>最后就是jsp了:<body><form method="post" action="student.do?op=delete" > <table border="1" align="center"> <tr> <th>学生编号</th> <th>学生姓名</th> <th>学生性别</th> <th>学生邮箱</th> <th>操作</th> </tr> <c:forEach var="student" items="${student}"> <tr> <td> <input type="hidden" value="${student.sid}" name="sid" /> ${student.sid} </td> <td>${student.sname}</td> <td>${student.ssex}</td> <td>${student.semail}</td> <td><input type="submit" value="删除" /></td> </tr> </c:forEach> </table></form> 没办法,老师说要熟悉struts1.x,精通2.xaction代码:// 删除 public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { StudentService service = new StudentService(); StudentForm studentForm = new StudentForm(); System.out.println(studentForm.getSid()); if (service.Delete(studentForm.getSid())) { response.getWriter().print("<script>alert('" + studentForm.getSname() + "删除成功!');</script>"); return mapping.findForward("to_index"); } return null; }form代码(有get和set了)public class StudentForm extends ActionForm { private Integer sid; private String sname; private Integer ssex; private String semail;然后配置文件:<struts-config> <form-beans> <form-bean name="StudentForm" type="com.accp.forms.StudentForm"></form-bean> </form-beans> <global-exceptions /> <global-forwards /> <action-mappings> <action name="StudentForm" path="/student" type="com.accp.actions.StudentAction" parameter="op"> <forward name="to_index" path="/index.jsp"></forward> </action> </action-mappings> <message-resources parameter="com.accp.ApplicationResources" /></struts-config>最后就是jsp了:<body><form method="post" action="student.do?op=delete" > <table border="1" align="center"> <tr> <th>学生编号</th> <th>学生姓名</th> <th>学生性别</th> <th>学生邮箱</th> <th>操作</th> </tr> <c:forEach var="student" items="${student}"> <tr> <td> <input type="hidden" value="${student.sid}" name="sid" /> ${student.sid} </td> <td>${student.sname}</td> <td>${student.ssex}</td> <td>${student.semail}</td> <td><input type="submit" value="删除" /></td> </tr> </c:forEach> </table></form>首先你的action能进去吗?其次你把你的get set方法发出来? 可以,action里我定义了一个Syso输出,输出的值是nullget和set:public Integer getSid() { return sid; } public void setSid(Integer sid) { this.sid = sid; } public String getSname() { return sname; } public void setSname(String sname) { this.sname = sname; } public Integer getSsex() { return ssex; } public void setSsex(Integer ssex) { this.ssex = ssex; } public String getSemail() { return semail; } public void setSemail(String semail) { this.semail = semail; } 问题是这里,你new出来的打印属性肯定是nullStudentForm studentForm = new StudentForm(); System.out.println(studentForm.getSid()); 所以:StudentForm studentForm = (StudentForm) form? 所以:StudentForm studentForm = (StudentForm) form?是的,试试看,1.x我有点忘了,反正不是new出来的 所以:StudentForm studentForm = (StudentForm) form?是的,试试看,1.x我有点忘了,反正不是new出来的能获取到了,但是我删除最后一个,编号是6,输出的却是1。哪出问题了? 急!!!jquery的validate插件与struts的冲突问题 请教上传头像的技术实现。 jsp 中如何使用ubb Timestamp类型问题.... 链接问题 cas修改用户验证问题 我十在找不出来哪里有问题.请大家帮帮我.急用. hibernate 一对一出错 帮帮忙吧.火烧眉毛了 executeUpdate的问题! response.sendRedirect中参数值是中文怎么传不了? eclipse中没有找到xfire 非常奇特的现象
没办法,老师说要熟悉struts1.x,精通2.xaction代码:// 删除
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
StudentService service = new StudentService();
StudentForm studentForm = new StudentForm();
System.out.println(studentForm.getSid());
if (service.Delete(studentForm.getSid())) {
response.getWriter().print("<script>alert('" + studentForm.getSname() + "删除成功!');</script>");
return mapping.findForward("to_index");
}
return null;
}form代码(有get和set了)public class StudentForm extends ActionForm {
private Integer sid;
private String sname;
private Integer ssex;
private String semail;然后配置文件:<struts-config>
<form-beans>
<form-bean name="StudentForm" type="com.accp.forms.StudentForm"></form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action name="StudentForm" path="/student"
type="com.accp.actions.StudentAction" parameter="op">
<forward name="to_index" path="/index.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="com.accp.ApplicationResources" />
</struts-config>
最后就是jsp了:<body>
<form method="post" action="student.do?op=delete" >
<table border="1" align="center">
<tr>
<th>学生编号</th>
<th>学生姓名</th>
<th>学生性别</th>
<th>学生邮箱</th>
<th>操作</th>
</tr>
<c:forEach var="student" items="${student}">
<tr>
<td>
<input type="hidden" value="${student.sid}" name="sid" />
${student.sid}
</td>
<td>${student.sname}</td>
<td>${student.ssex}</td>
<td>${student.semail}</td>
<td><input type="submit" value="删除" /></td>
</tr>
</c:forEach>
</table>
</form>
没办法,老师说要熟悉struts1.x,精通2.xaction代码:// 删除
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
StudentService service = new StudentService();
StudentForm studentForm = new StudentForm();
System.out.println(studentForm.getSid());
if (service.Delete(studentForm.getSid())) {
response.getWriter().print("<script>alert('" + studentForm.getSname() + "删除成功!');</script>");
return mapping.findForward("to_index");
}
return null;
}form代码(有get和set了)public class StudentForm extends ActionForm {
private Integer sid;
private String sname;
private Integer ssex;
private String semail;然后配置文件:<struts-config>
<form-beans>
<form-bean name="StudentForm" type="com.accp.forms.StudentForm"></form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action name="StudentForm" path="/student"
type="com.accp.actions.StudentAction" parameter="op">
<forward name="to_index" path="/index.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="com.accp.ApplicationResources" />
</struts-config>
最后就是jsp了:<body>
<form method="post" action="student.do?op=delete" >
<table border="1" align="center">
<tr>
<th>学生编号</th>
<th>学生姓名</th>
<th>学生性别</th>
<th>学生邮箱</th>
<th>操作</th>
</tr>
<c:forEach var="student" items="${student}">
<tr>
<td>
<input type="hidden" value="${student.sid}" name="sid" />
${student.sid}
</td>
<td>${student.sname}</td>
<td>${student.ssex}</td>
<td>${student.semail}</td>
<td><input type="submit" value="删除" /></td>
</tr>
</c:forEach>
</table>
</form>首先你的action能进去吗?
其次你把你的get set方法发出来?
可以,action里我定义了一个Syso输出,输出的值是null
get和set:public Integer getSid() {
return sid;
} public void setSid(Integer sid) {
this.sid = sid;
} public String getSname() {
return sname;
} public void setSname(String sname) {
this.sname = sname;
} public Integer getSsex() {
return ssex;
} public void setSsex(Integer ssex) {
this.ssex = ssex;
} public String getSemail() {
return semail;
} public void setSemail(String semail) {
this.semail = semail;
}
StudentForm studentForm = new StudentForm();
System.out.println(studentForm.getSid());
所以:StudentForm studentForm = (StudentForm) form?
所以:StudentForm studentForm = (StudentForm) form?是的,试试看,1.x我有点忘了,反正不是new出来的
所以:StudentForm studentForm = (StudentForm) form?是的,试试看,1.x我有点忘了,反正不是new出来的能获取到了,但是我删除最后一个,编号是6,输出的却是1。哪出问题了?