struts2配置文件中的method={1}详解
生活随笔
收集整理的這篇文章主要介紹了
struts2配置文件中的method={1}详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
struts.xml中的配置:
<!-- 配置用戶模塊的action --><action name="user_*" class="userAction" method="{1}"><result name="registPage">/WEB-INF/jsp/regist.jsp</result></action>/*
此時method={1}中的{1}代表user_*中的*,即加入你訪問路徑是/user_registPage.action,則此刻訪問的是該Action中的registPage方法。同理,如果通配符* == delete,則就訪問的是delete方法。
當name中含有多個通配符的時候,method={2} ,就代表第二個通配符,同理以此類推。
這種方式更靈活的簡化了struts.xml的配置文件。
*/regist.jsp頁面中的代碼段:
<li id="headerRegister" class="headerRegister" style="display: list-item;"><a href="${ pageContext.request.contextPath }/user_registPage.action">注冊</a>|</li>/*
user_registPage.action對應 name="user_*",通配符*就是registPage,
method="{1}"里面的{1}就是代表registPage()方法,
這個registPage()方法存在于 UserAction中*/Action類:public class UserAction extends ActionSupport{/*** 跳轉到注冊頁面的執行方法*/
public String registPage(){ return "registPage";}
}
?
?
<action name="*_*" method="{2}" class="action.{1}Action">
上面代碼定義了一個模式為*_*的action,只要匹配該模式的請求,都可以被該Action處理。
如果有URL為BOOK_save.action請求,因為匹配了*_*模式,第一個*為BOOK,第二個8為save,
則調用action.BOOKAction處理類中的save()方法來處理用戶請求。
轉載于:https://www.cnblogs.com/fifiyong/p/6027565.html
總結
以上是生活随笔為你收集整理的struts2配置文件中的method={1}详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pl/sql developer执行光标
- 下一篇: HDU 5115 Dire Wolf 区