actionform是个父类,为什么可以直接向下转型到RegisterForm public class RegisterForm extends ActionForm {。}public class RegisterAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest req,
HttpServletResponse res) {
// ○1 将form 转型为RegisterForm
RegisterForm rf = (RegisterForm) form;
String username = rf.getUsername();
String password1 = rf.getPassword1();
String password2 = rf.getPassword2();
ActionForward forward = new ActionForward();
.....
}

解决方案 »

  1.   

    因为他实际传的就是RegisterForm,如果实际传递的不是RegisterForm就报错了哈哈
      

  2.   

    怎么知道实际传的就是RegisterForm?
      

  3.   


    因为你的jsp的form表单把它注册成了RegisterForm,这个是你做的
      

  4.   

    因为actionform 就是 RegisterForm! 
      

  5.   

    如果没有猜错的话,施主应该是用的Struts,看看Struts的配置文件:
    Form -Action-Forward
    对应此RegisterAction 的form是不是RegisterForm
      

  6.   

    <action path="/register" type="app.RegisterAction"
    name="RegisterForm" scope="request" input="/register.jsp">指的是这个name的值吗?