Struts-config.xml配置文件《action-mappings》元素的详解
原文地址:http://blog.163.com/sara1124@126/blog/static/11291097020105125537114/
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被用作在應用程序編譯好后充當系統參數,只需要更改這個配置文件而不需要重新編譯系統。
轉載于:https://www.cnblogs.com/jearay/p/3715771.html
總結
以上是生活随笔為你收集整理的Struts-config.xml配置文件《action-mappings》元素的详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: eclipse/MyEclipse 日期
- 下一篇: mybatis 模糊查询