Struts学习之动态表单

1、与普通表单不同之处之基类为

org.apache.struts.action.DynaActionForm

2、与普通表单不同之处之struts-config.xml

  <form-bean name="userForm" type="org.apache.struts.action.DynaActionForm" >
        <!--该表单的属性需要配置如下-->
        <form-property name="name" type="java.lang.String"/>
        <form-property name="passwd" type="java.lang.String"/>
        <form-property name="email" type="java.lang.String"/>
    </form-bean>

3、访问表单数据不同之处之Action

public ActionForward register(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        DynaActionForm userForm = (DynaActionForm) form;// TODO Auto-generated method stub
        //从动态表单中取出数据
        String name = userForm.getString("name");
        String password = userForm.getString("passwd");
        String email = userForm.getString("email");
        
        System.out.println(name + ":" + password + ":" + email);
        
        return mapping.findForward("ok");
    }

 

posted @ 2015-04-24 23:31  机器蜗牛  阅读(280)  评论(0编辑  收藏  举报