Struts-config.xml配置文件《action-mappings》元素的详解



Struts配置文件的详细解析


ction-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子元素。除了pathtypename属性外,action还具有如下属性:

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

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

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

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

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

forward属性也是可选的。

action元素定义举例如下:

Example1.

Eg2. input属性的例子:

[XML]  view plain  copy
 print ?
  1. <p><action-mappings></p><p>    <action   
  2.   
  3.      path="/userAction"   
  4.   
  5.      type="com.amigo.struts.action.UserAction"   
  6.   
  7.      name="UserForm"  
  8.   
  9.      scope="request"  
  10.   
  11.      validate = "false"  
  12.   
  13.      parameter="method" >   
  14.   
  15.      <forward name="error" path="/user/error.jsp" />  
  16.   
  17.      <forward name="success" path="/user/success.jsp"/>  
  18.   
  19.      <forward name="add" path="/user/addUser.jsp"/>  
  20.   
  21.      <forward name="update" path="/user/updateUser.jsp"/>  
  22.   
  23.      <forward name="list" path="/user/userList.jsp"/>  
  24.   
  25.     </action>  
  26.   
  27. </action-mappings></p>  

你可能感兴趣的:(Struts-config.xml配置文件《action-mappings》元素的详解)