Struts 动态FORM实现过程

1修改struts-config.xml中<form-beans>  
<form-beans>    
  <form-bean name="regeditForm" type="org.apache.struts.action.DynaActionForm">
  <form-property name="username" type="java.lang.String"/>
  <form-property name="password" type="java.lang.String"/>
  </form-bean>
  </form-beans>
---------------------------------------------------------------------------
2修改struts-config.xml中action配置
<action name="regeditForm"............
---------------------------------------------------------------------------
3 action中导包
import org.apache.struts.action.DynaActionForm;
--------------------------------------------------------------------------
4 action的excute方法中导入包

    DynaActionForm userActionForm=(DynaActionForm)actionForm;
  修改execute方法  
    String username = (String)userActionForm.get("username");
    String password = (String)userActionForm.get("password");
------------------------------------------------------------------------
注意:如果是数组参数
在struts-config.xml中
<form-bean name="tryidactionform"
type="org.apache.struts.action.DynaActionForm">
<form-property name="checkbox" type="java.lang.String[]"></form-property>
</form-bean>
在页面表单中复选框的名字对应为checkbox,并且表单用<html:form></html:form>
然后在action中,String[] items = (String[])form.get("checkbox");
这样就可以了
posted @ 2010-12-20 22:02  左正  阅读(286)  评论(0编辑  收藏  举报