在struts中有form类和services类还有actions类,配置文件也写好了对应的<form-beans>和<action-mapping>,可是还是取不到值,怎么回事?小弟刚学struts。。

解决方案 »

  1.   

    还在用struts1.x啊。。好老的,你这样说也没法给你找问题,至少来点代码
      

  2.   


    没办法,老师说要熟悉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>
      

  3.   


    没办法,老师说要熟悉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方法发出来?
      

  4.   


    可以,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;
    }
      

  5.   

    问题是这里,你new出来的打印属性肯定是null
    StudentForm studentForm = new StudentForm();
            System.out.println(studentForm.getSid());
      

  6.   


    所以:StudentForm studentForm = (StudentForm) form?
      

  7.   


    所以:StudentForm studentForm = (StudentForm) form?是的,试试看,1.x我有点忘了,反正不是new出来的
      

  8.   


    所以:StudentForm studentForm = (StudentForm) form?是的,试试看,1.x我有点忘了,反正不是new出来的能获取到了,但是我删除最后一个,编号是6,输出的却是1。哪出问题了?