• 【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>
  • 相关阅读:
    YearsBetween、MonthsBetween ... YearSpan、MonthSpan ... 间隔时间
    SysUtilsFunction
    DateOf、TimeOf、YearOf、MonthOf、WeekOf、DayOf、HourOf、MinuteOf、SecondOf、MilliSecondOf 提取时间成分
    MathFunction
    DateUtilsFunction
    关于发表评论时的“无法验证数据”的错误
    用ISAPI_Rewrite实现反向代理(ReverseProxy)
    [公告]取消了后台管理中的统计功能
    推荐一个不错的SharePoint文档库树形显示WebPart及谈谈写Blog的好处
    [公告]镜像站点可以登录并发表文章
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/12309994.html
Copyright © 2020-2023  润新知