打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Struts-config.xml配置文件《action-mappings》元素的详解 -...
Struts-config.xml配置文件《action-mappings》元素的详解 [转贴 2010-02-03 11:41:34]
 
 
字号:

action-mappings

       该元素用于将Action元素定义到ActionServlet类中,它含有0到多个<action/>元素,其格式如下:

<action-mappings>

<action path="Action请求的相对路径,与页面<html:form>的Action属性值一致"

type="该Action的对应类的全路径"

name="该Action绑定的FormBean,与<form-bean >的Name属性值一致"

<forward name="与Action类中mapping.findForward("mapname")返回的mapname值一致" path="页面跳转的相对路径"/>

</action>

</action-mappings>

       每个action子元素可包含一个或多个forward子元素。除了path、type和name属性外,action还具有如下属性:

l         scope:指定ActionForm Bean的作用域(session和request),缺省为session。(可选);

l         input:当Bean发生错误时返回的路径,在validate验证框架中错误显示的页面(可选);

l         classname:指定一个调用这个Action类的ActionMapping类的全名。缺省用org.apache.struts.action.ActionMapping(可选);

l         include:如果没有forward的时候,它起forward的作用(可选);

l         validate:若为true,则会调用ActionForm的validate()方法或调用validate验证,否则不调用,缺省为true(可选)。

forward属性也是可选的。

action元素定义举例如下:

Example1.

Eg2. 有input属性的例子:

<action-mappings>    <action

     path="/userAction"

     type="com.amigo.struts.action.UserAction"

     name="UserForm"

     scope="request"

     validate = "false"

     parameter="method" >

     <forward name="error" path="/user/error.jsp" />

     <forward name="success" path="/user/success.jsp"/>

     <forward name="add" path="/user/addUser.jsp"/>

     <forward name="update" path="/user/updateUser.jsp"/>

     <forward name="list" path="/user/userList.jsp"/>

    </action>

</action-mappings>

Eg3. 仅有JSP的action元素:

<action-mappings>

    <action path="/calcAction"

    type="com.amigo.struts.action.CalcAction"

    name="CalcForm"

    scope="request"

    validate="true"

    input="/index.jsp">

    <forward name="success" path="/success.jsp"/>
    <forward name="error" path="/error.jsp"/>

    </action>

</action-mappings>

首先,ActionServlet接到请求后调用ForwardAction的execute()方法,execute()根据配置的parameter属性值来forward到那个URI。

<action path="/menu"

    parameter="/default.jsp"

    type="org.apache.struts.actions.ForwardAction" />

这样做的效果是:没有任何form被实例化,比较现实的情形可能是form在request更高级别的范围中定义;或者这个action被用作在应用程序编译好后充当系统参数,只需要更改这个配置文件而不需要重新编译系统。


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhoukang0916/archive/2009/05/23/4210029.aspx

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
structs中基本配置入门
Struts的配置文件
Struts-config.xml配置文件讲解
struts1 Action原理与配置
struts1配置文件中action的常用属性
再说Struts多模块开发
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服