• 【Struts 动态表单】DynaActionForm


    RegisterAction
    package k.action;
    
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.DynaActionForm;
    import org.apache.struts.actions.DispatchAction;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class RegisterAction extends DispatchAction {
        public ActionForward doRegister(ActionMapping mapping, ActionForm form,
                                         HttpServletRequest request, HttpServletResponse response) throws Exception {
            DynaActionForm dynaForm = (DynaActionForm) form;
            String userName = dynaForm.getString("userName");
            String password = dynaForm.getString("password");
            String mobile = dynaForm.getString("mobile");
            System.out.println("==" + userName + "==" + password + "==" + mobile);
            return mapping.findForward("registerOk");
        }
    }

    struts-config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
            "http://struts.apache.org/dtds/struts-config_1_3.dtd">
    <struts-config>
        <form-beans>
            <form-bean name="userForm2" type="org.apache.struts.action.DynaActionForm">
                <form-property name="userName" type="java.lang.String"></form-property>
                <form-property name="password" type="java.lang.String"></form-property>
                <form-property name="mobile" type="java.lang.String"></form-property>
            </form-bean>
        </form-beans>
        <action-mappings>
            <action name="userForm2" path="/register" parameter="action" type="k.action.RegisterAction"
                    scope="request" attribute="userForm" input="index.jsp" validate="false">
                <forward name="registerOk" path="/WEB-INF/jsp/registerOk.jsp"></forward>
            </action>
        </action-mappings>
    </struts-config>

    register.jsp

    <h1>登录页面</h1>
    <form action="${APP_PATH}/register.do?action=doRegister" method="post">
        账号:<input type="text" name="userName" value="11哈哈"> <br>
        密码: <input type="password" name="password" value="1"> <br>
        手机: <input type="text" name="mobile" value="13612341234"> <br>
        <input type="submit" value="submit"> <br>
    </form>

    registerOk.jsp

    <h1>注册成功</h1>
  • 相关阅读:
    安装vim
    linux输入法
    freemarker 超出字符用省略号表示
    三维数组去重
    php 相同的产品 一个背景色
    php 判断白天黑夜
    PHP-preg_replace过滤字符串代码
    checkbox 更新回显
    php socket编程入门
    命令行执行php
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/12309994.html
Copyright © 2020-2023  润新知