轉自 http://blog.csdn.net/mjl960108/article/details/53523676
<action name= "Login_*" method= "{1}" class= "mailreader2.Login">
中Login_*帶*是什麼意思?method= “{1} “帶{}這個是什麼意思?
解答:
name= “Login_* ”
代表這個action處理所有以Login_開頭的請求
method= “{1} ”
根據前面請求Login_methodname,調用action中的以methodname命名的方法
class= “mailreader2.Login ”
action的類名稱
如jsp文件中請求Login_validateUser的action名稱,根據上面配置,調用action類mailreader2.Login類中方法validateUser()
又如:
對於Login_update請求,將會調用mailreader2.Login的update()方法。
Action Wildcard(Action 通配符)
配置:
<package name="actions" extends="struts-default" namespace="/actions">
<action name="Student*" class="com.bjsxt.struts2.action.StudentAction" method="{1}">
<result>/Student{1}_success.jsp</result>
</action>
<action name="*_*" class="com.bjsxt.struts2.action.{1}Action" method="{2}">
<result>/{1}_{2}_success.jsp</result>
<!-- {0}_success.jsp -->
</action>
</package>
{1}、{2}表示第一第二個佔位符
*爲通配符
通過action name的通配匹配,獲得佔位符,可以使用佔位符放在result和method、class中替代匹配的字符。
總結:
使用通配符,將配置量降到最低。
<a href="<%=context %>/actions/Studentadd">添加學生
<a href="<%=context %>/actions/Studentdelete">刪除學生
<a href="<%=context %>/actions/Teacher_add">添加老師
<a href="<%=context %>/actions/Teacher_delete">刪除老師
<a href="<%=context %>/actions/Course_add">添加課程
<a href="<%=context %>/actions/Course_delete">刪除課程
不過,一定要遵守”約定優於配置”的原則。