标签:struts动态表单的创建 struts动态表单 动态表单的创建 struts
<body> <form action="/DynamicForm/register.do?flag=register" method="post"> u:<input type="text" name="name"/><br/> p:<input type="password" name="password"/><br/> <input type="submit" value="注册用户" /> </form> </body>
<?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> <!-- 动态创建表单 表单是配置出来的 不是定义出来的--> <!-- 这里的type是在 Struts 1.3 Libraries中的struts-core-1.3.8.jar 下的DynaActionForm.class的路径--> <form-bean name="userForm" type="org.apache.struts.action.DynaActionForm"> <!-- 这里的name即是表单中的属性 --> <form-property name="name" type="java.lang.String" /> <form-property name="password" type="java.lang.String" /> <form-property name="name" type="java.lang.String" /> </form-bean> </form-beans> <global-exceptions /> <global-forwards /> <action-mappings> <action attribute="userForm" input="/WEB-INF/register.jsp" name="userForm" parameter="flag" path="/register" scope="request" type="com.lc.struts.action.RegisterAction" cancellable="true" > <forward name="registerok" path="/WEB-INF/ok.jsp" /> </action> </action-mappings> <message-resources parameter="com.lc.struts.ApplicationResources" /> </struts-config>
package com.lc.struts.action; //导包即可 public class RegisterAction extends DispatchAction { public ActionForward register(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { DynaActionForm userForm = (DynaActionForm) form; /* * 从动态表单中取出数据的方法 */ String name = userForm.get("name").toString(); String password = userForm.get("password").toString(); System.out.println(name+""+password+""); return mapping.findForward("registerok"); //成功后返回的页面 } }
标签:struts动态表单的创建 struts动态表单 动态表单的创建 struts
原文地址:http://blog.csdn.net/xlgen157387/article/details/39550867