package com.hgq.student_information.web.struts.action;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;import com.hgq.student_information.dao.DAOFactory;
import com.hgq.student_information.dao.TeacherDAO;
import com.hgq.student_information.domain.Student;
import com.hgq.student_information.domain.Teacher;
import com.hgq.student_information.web.struts.form.StudentForm;
import com.hgq.student_information.web.struts.form.TeacherForm;public class EditTeacher extends Action{
private TeacherDAO teaDao; public TeacherDAO getTeacherDAO() {
return DAOFactory.getInstance().createTeacherDAO();
} /**
 * Method execute
 * 
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

String id = (String)request.getParameter("teacher_id");

/*
 * 声明一个StudentForm类型的对象. form为页面中提交的表单信息,将它
 * 强制转换为StudentForm类型,并赋值给stuForm对象
 */
TeacherForm teaForm = (TeacherForm) form ;  // 错误代码 teaDao = this.getTeacherDAO();
// 根据ID获取学生信息
Teacher tea = teaDao.getTeacherByID(id);

// 设置相应的更新属性
tea.setName( teaForm.getName());
tea.setPassword( teaForm.getPassword());
tea.setXuebu( teaForm.getXuebu());
tea.setSex( teaForm.getSex() );
tea.setTitle(teaForm.getTitle());
tea.setTel( teaForm.getTel()) ;
tea.setEmail( teaForm.getEmail()) ;

if(teaDao.updateTeacher(tea)){
// 更新成功,跳转页面
return (mapping.findForward("success"));
}else {

return (mapping.getInputForward());
}

}
}
代码我已经继承Action类了..为什么还会出现这个错误...
最奇怪的是..之前有个类也是试用此代码..都没有错误.
就这个类的代码出现这个错误...求高手解答..

解决方案 »

  1.   

    struts-config.xml也贴出来啊。
    估计是<action name="这个地方填错了。。">
      

  2.   

    关键是你的TeacherForm 怎么写的,是集成了ActionForm吗?奇怪了,TeacherForm 和你的Action有啥关系
      

  3.   

    问题是你的form没有继承actionForm
      

  4.   

    package ActionForm;
    import org.apache.struts.action.ActionForm;
    public class BookForm extends ActionForm{
         private  String bookid;
         private  String bookname;
         private  String bookprice;
         public void setBookid(String bookid){
          this.bookid = bookid;
         }
         public String getBookid(){
          return bookid;
         }
         public void setBookname(String bookname){
          this.bookname = bookname;
         }
         public String getBookname(){
          return bookname;
         }
         public void setBookprice(String bookprice){
          this.bookprice = bookprice;
         }
         public String getBookprice(){
          return bookprice;
         }
    }
    我也出现了这样的问题,可能你的TeacherForm应该继承ActionForm类似于我这段代码