`

Struts Action ActionForm 分类

阅读更多
Struts Action ActionForm 分类
ForwardAction:
ForwardAction作用:就是为一个单独jsp文件配置一个别名,程序开发中有部分人提出这么一个概念:将程序中所有的JSP文件存放在WEB-INF下,之后每个JSP页面之前不能直接联系。
    a.jsp -> *.do -> b.jsp
ForwardAction的配置只需要在struts-config.xml中配置完成。
<action path="/hel" type="org.apache.struts.actions.ForwardAction" 
parameter="/WEB-INF/AdvToken.jsp" />

DispatchAction:
   通过form的hidden域或action=*.do?传递,例如:
<input type="hidden" name="status" value="insert" />
struts-config.xml中配置action,加个parameter="status"属性
<action
      attribute="demoForm"
      input="/form/demo.jsp"
      name="demoForm"
      path="/demo"
      scope="request"
      type="com.metarnet.han.struts.action.DemoAction"
      parameter="status" />
DemoAction extends DispatchAction 中方法名使用
form的hidden域或action=*.do?传递的status的value的名称。

动态ActionForm: org.apache.struts.action.DynaActionForm
不用生成Form文件,Form的属性通过struts-config.xml中的form bean设置,如下:
<form-bean name="mldnForm" type="org.apache.struts.action.DynaActionForm" >
    <form-property name="name" type="java.lang.String"></form-property>
    <form-property name="password" type="java.lang.String"></form-property>
</form-bean>
Action中 使用demoForm.getString("name") 取值。

动态可验证ActionForm:org.apache.struts.validator.DynaValidatorForm
不仅不用生成Form文件,还可以给Form验证,Form的属性通过struts-config.xml中的form bean设置,
如下:
<form-bean name="hanForm" type="org.apache.struts.validator.DynaValidatorForm">
      <form-property name="password" type="java.lang.String" />
      <form-property name="name" type="java.lang.String" />
</form-bean>

使用验证插件,新建Struts 1.3 Plugin,struts-config.xml中内容如下:
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>

struts 1.3中WEB-INF下没有validator-rules.xml,我从struts 1.3 lib ->struts-core ->
-> org.apache.struts.validator下复制到WEB-INF下面的。
/WEB-INF/validation.xml内容:
<!DOCTYPE form-validation PUBLIC
        "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN"
        "http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd">
<form-validation>
<formset>
   <form name="hanForm">
    <field property="name" depends="required">
     <arg key="err.name" resource="true" />
    </field>
    <field property="password" depends="required" >
     <arg key="err.password" resource="true" />
    </field>
   </form>
</formset>
</form-validation>

ApplicationResources.properties 中对应:
err.name        = \u59D3\u540D
err.password    = \u5BC6\u7801
errors.required = {0} \u4E0D\u80FD\u4E3A\u7A7A\uFF01\uFF01\uFF01~~~~

Action中 使用demoForm.getString("name") 取值。

分享到:
评论

相关推荐

    struts中ActionForm的validate方法使用小得

    struts提供了标签来显示整个ActionErrors的错误信息。但要在struts-config.xml中设置&lt;action ...

    Struts中不同的Action和ActionForm组合.rar

    Struts中不同的Action和ActionForm组合.rar

    struts的教程.doc

    Struts ActionServlet控制器对象 8 Struts Action Classes 8 Struts Action Mapping 9 使用ActionForward导航 10 Struts ActionForm Bean捕获表单数据 11 Struts的其他组件 12 Validation Framework for ...

    org.apache.struts缺少所需包

    import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.DispatchAction等缺少

    java Struts教程

    Struts ActionServlet控制器对象 8 Struts Action Classes 8 Struts Action Mapping 9 使用ActionForward导航 10 Struts ActionForm Bean捕获表单数据 11 Struts的其他组件 12 Validation Framework for Struts 12 ...

    struts 教程 很好很详细

    Struts ActionServlet控制器对象 8 Struts Action Classes 8 Struts Action Mapping 9 使用ActionForward导航 10 Struts ActionForm Bean捕获表单数据 11 Struts的其他组件 12 Validation Framework for Struts 12 ...

    Struts2 in action中文版

    14.1.2 ActionForm怎么了 292 14.1.3 切换标签库 293 14.1.4 拆分消息资源 294 14.2 逐步转换 296 14.2.1 逐步实现 296 14.2.2 动作映射 298 14.2.3 动作在哪里遇到表单 300 14.2.4 转换页面 301 14.2.5 不说英语 ...

    Struts1框架执行原理(附Action、ActionServlet、ActionForm工作机制)

    有助于加强我们对Struts1的理解和学习,让我们从原理把握Struts1之后可以更方便更容易的学习Struts2

    struts 入门教程

    Struts ActionServlet控制器对象 8 Struts Action Classes 8 Struts Action Mapping 9 使用ActionForward导航 10 Struts ActionForm Bean捕获表单数据 11 Struts的其他组件 12 Validation Framework for Struts 12 ...

    Struts in Action[文字版][中文]

    书名:Struts in Action[文字版][中文](电子书) 格式:PDF 本书的目的是帮助Web应用开发者能够最好的使用 Struts web 应用框架。 Struts是一个开源软件,有助于开发者更加快速和容易地建立Web应用程序。Struts依靠...

    Struts简介 什么是Struts Struts基本运作流程

    Struts简介 什么是Struts Struts基本运作流程 ActionMapping类 Action类 ActionForm类 ActionError与ActionMessage 协同开发 模块化程序 Struts异常处理 Struts国际化支持 PlugIn接口 等等

    [摘]Struts 学习笔记之ActionForm

    比上面的完整 博文链接:https://shangdiyefankun.iteye.com/blog/122443

    struts2配置详解

    4、Struts1 中, Action 类必须继承 org.apache.struts.action.Action 类; Struts2 中任何一个 POJO 都可以是一个 Action 类. 5、Struts2 在页面里使用 OGNL 来显示各种对象模型, 可以不再使用 EL 和 JSTL

    struts 的jar包

    apache的struts 的jar包 ,J2EE框架开发愿意和大家分享。

    Struts_开发的最佳实践

    应用程序的 ActionForm 扩展了 Struts 的 org.apache.struts.action.ActionForm 类。ActionForm 是一些封装和验证请求参数的简单 JavaBean。要验证请求数据,ActionForm 的 validate() 方法必须给出一个特定于该情况...

    Struts2教程

    3. 编写 ActionForm 类(一般从 org.apache.struts.action.ActionForm 类继承),这一步 不是必须的,如果要接收客户端提交的数据,需要执行这一步。 4. 在 struts-config.xml 文件中配置 Action 和 ActionForm 。 5...

    StrutsAction

    最简单的Struts例子,只用了Action和ActionForm 具体内容参见Giddy的Blog http://giddyandyang.spaces.live.com/

    struts课堂资料\第五章(动态ActionForm与控制器)

    struts课堂资料\第五章(动态ActionForm与控制器)

    struts面试宝典.pdf

    在Struts中,用户的请求一般以*.do作为请求服务名,所有的请求均被指向ActionServlet,ActionServlet根据Struts-config.xml中的配置信息,将用户请求封装成一个指定名称的ActionForm,并将此ActionForm传至指定的...

    Struts中文手册[文字版][中文]

    1.7. ActionForm类9 1.8. ActionForward 类.10 1.9. 错误处理.11 1.9.1. ActionError类11 1.9.2. ActionError类11 2. Struts 标记库13 2.1. Bean 标记.13 2.1.1. Bean 复制标记13 2.1.2. 定义脚本变量的标记.14 ...

Global site tag (gtag.js) - Google Analytics