Struts-config.xml配置文件《action-mappings》元素的详解
原文地址:http://blog.163.com/sara1124@126/blog/static/11291097020105125537114/
action-mappings
?????? 該元素用于將Action元素定義到ActionServlet類中,它含有0到多個(gè)<action/>元素,其格式如下:
<action-mappings>
<action path="Action請(qǐng)求的相對(duì)路徑,與頁(yè)面<html:form>的Action屬性值一致"
type="該Action的對(duì)應(yīng)類的全路徑"
name="該Action綁定的FormBean,與<form-bean >的Name屬性值一致"
<forward name="與Action類中mapping.findForward("mapname")返回的mapname值一致" path="頁(yè)面跳轉(zhuǎn)的相對(duì)路徑"/>
</action>
</action-mappings>
?????? 每個(gè)action子元素可包含一個(gè)或多個(gè)forward子元素。除了path、type和name屬性外,action還具有如下屬性:
l???????? scope:指定ActionForm Bean的作用域(session和request),缺省為session。(可選);
l???????? input:當(dāng)Bean發(fā)生錯(cuò)誤時(shí)返回的路徑,在validate驗(yàn)證框架中錯(cuò)誤顯示的頁(yè)面(可選);
l???????? classname:指定一個(gè)調(diào)用這個(gè)Action類的ActionMapping類的全名。缺省用org.apache.struts.action.ActionMapping(可選);
l???????? include:如果沒(méi)有forward的時(shí)候,它起forward的作用(可選);
l???????? validate:若為true,則會(huì)調(diào)用ActionForm的validate()方法或調(diào)用validate驗(yàn)證,否則不調(diào)用,缺省為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接到請(qǐng)求后調(diào)用ForwardAction的execute()方法,execute()根據(jù)配置的parameter屬性值來(lái)forward到那個(gè)URI。
<action path="/menu"
??? parameter="/default.jsp"
??? type="org.apache.struts.actions.ForwardAction" />
這樣做的效果是:沒(méi)有任何form被實(shí)例化,比較現(xiàn)實(shí)的情形可能是form在request更高級(jí)別的范圍中定義;或者這個(gè)action被用作在應(yīng)用程序編譯好后充當(dāng)系統(tǒng)參數(shù),只需要更改這個(gè)配置文件而不需要重新編譯系統(tǒng)。
轉(zhuǎn)載于:https://www.cnblogs.com/jearay/p/3715771.html
總結(jié)
以上是生活随笔為你收集整理的Struts-config.xml配置文件《action-mappings》元素的详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: eclipse/MyEclipse 日期
- 下一篇: mybatis 模糊查询