如何使用DynaActionForm

本文介绍如何使用Struts2中的DynaActionForm实现动态表单,通过配置struts-config.xml文件来动态生成表单内容,避免频繁修改代码。文章还探讨了DynaActionForm的验证方式及其实现。
DynaActionForm动态form可以不局限于某一个html表单页面,当表单页面内容增加或减少中,只需修改struts-config.xml文件即可生成新的form,免去了重新编译form的烦恼
 
JSP页面
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
<title>
jsp3
</title>
</head>
<body bgcolor="#ffffff">
<html:form action="/insertAction3.do">
  name:
<html:text property="name"/>
  pass:
<html:text property="password"/>
  
<html:submit>submit
  
</html:submit>
</html:form>
</body>
</html>
 
struts-config.xml文件内容
<struts-config>
  
<form-beans> 
    
<form-bean name="loginForm" dynamic="true" 
        type
="org.apache.struts.action.DynaActionForm">
      
<form-property name="name" type="java.lang.String" />
      
<form-property name="password" type="java.lang.String" />
    
</form-bean>
  
</form-beans>
  
<action-mappings>
  
<action scope="session" name="loginForm" path="/insertAction3" 
      type
="untitled2.InsertAction3" validate="false" />
  
</action-mappings>
  
<message-resources parameter="ApplicationResources" />
</struts-config>
 
注:动态表单是配置出来的,其reset()方法不执行任何操作,validate()方法也没有提  供任何默认的验证行为,可以通过建立DynaActionForm子类覆盖validate()方法,  但这样做违背了DynaActionForm的初衷-用配置代替编程,所以  
  DynaActionForm的验证由Validator框架完成最好
 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值