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();
.....
}
{
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();
.....
}
因为你的jsp的form表单把它注册成了RegisterForm,这个是你做的
Form -Action-Forward
对应此RegisterAction 的form是不是RegisterForm
name="RegisterForm" scope="request" input="/register.jsp">指的是这个name的值吗?