在struts.xml配置文件中遇到了param,有點迷糊,上網查了查……彷佛明白些了html
<action name="Log*" method="loginFrame{1}" class="member.loginIndeAct">
<result>${tplPath}</result>
<result name="logout" type="redirectAction">
<param name="namespace">/jeecms</param>
<param name="actionName">LoginFrameInput</param>
</result>
</action>java
這裏的action 是Log,他包含了登錄和退出,當系統在登陸的時候就直接返回${tplPath}就能夠了;在退出的時候須要返回到登錄頁面,因此退出的時候是轉發到 action的,轉發到action確定要告訴系統轉發到那個action,該action的namespace是什麼,名字是什麼,就是經過param 該屬性老告知struts2的;固然param還有其餘用法,不過通常就用這個就差很少了,綜上得出:express
param標籤主要用於爲其餘標籤提供參數,例如bean和include標籤。
param參數設置:
name:可選屬性,指定設置參數名稱
value:可選屬性,指定參數的值
id:可選屬性,指定該元素引用idapache
看到這,野豬彷佛感受清楚了許多,嘿嘿……json
下面還搜到了一些信息,等野豬不是很清楚的時候再看看吧……瀏覽器
chain
用來處理Action鏈,被跳轉的action中仍能獲取上個頁面的值,如request信息。
com.opensymphony.xwork2.ActionChainResult
dispatcher
用來轉向頁面,一般處理JSP
org.apache.struts2.dispatcher.ServletDispatcherResult
freemaker
處理FreeMarker模板
org.apache.struts2.views.freemarker.FreemarkerResult
httpheader
控制特殊HTTP行爲的結果類型
org.apache.struts2.dispatcher.HttpHeaderResult
stream
向瀏覽器發送InputSream對象,一般用來處理文件下載,還可用於返回AJAX數據
org.apache.struts2.dispatcher.StreamResult
velocity
處理Velocity模板
org.apache.struts2.dispatcher.VelocityResult
xslt
處理XML/XLST模板
org.apache.struts2.views.xslt.XSLTResult
plainText
顯示原始文件內容,例如文件源代碼
org.apache.struts2.dispatcher.PlainTextResult
plaintext
顯示原始文件內容,例如文件源代碼
org.apache.struts2.dispatcher.PlainTextResult
redirect
重定向到一個URL ,被跳轉的頁面中丟失傳遞的信息,如request
org.apache.struts2.dispatcher.ServletRedirectResult
redirectAction
重定向到一個Action ,跳轉的頁面中丟失傳遞的信息,如request
org.apache.struts2.dispatcher.ServletActionRedirectResult
redirect-action
重定向到一個Action ,跳轉的頁面中丟失傳遞的信息,如request
org.apache.struts2.dispatcher.ServletActionRedirectResult
注:redirect與redirect-action區別jsp
1、使用redirect須要後綴名 使用redirect-action不須要後綴名
2、type="redirect" 的值能夠轉到其它命名空間下的action,而redirect-action只能轉到同一命名空下的 action,所以它能夠省略.action的後綴直接寫action的名稱。
如:ide
<result name="success" type="redirect">viewTask.action</result>
<result name="success" type="redirect-action">viewTask</result>this
附:redirect-action 傳遞參數 url
由於使用了redirect-action,因此要注意不能將 showpreinf?preinfo.order_number=${preinfo.order_number}寫成 showpreinf.action?preinfo.order_number=${preinfo.order_number}
其中${}爲EL表達式,獲取action:enterpreinfo中屬性的值;在這個配置文件裏,多個參數的鏈接符使用了"&",但XML的語法規範,應該使用"&"代替"&",原理和HTML中的轉義相同,開始沒有注意,在struts分析配置文件時,老是報出這樣的錯誤:
json 通常很容易忽略的一個地方(在EXT中很是有用) 示例
- <package name="struts2" extends="json-default" namespace="/">
- <action name="login" class="loginAction" method="login">
- <result type="json">
- <param name="includeProperties">success,result</param>
- </result>
- </action>
- <action name="main" class="loginAction" method="main">
- <result name="main">/index.jsp</result>
- </action>
- </package>
- private boolean success = true;
- private String result = "main.action";
- //getter和setter方法略
以上的success和result互相對應到了
- <param name="includeProperties">success,result</param>
struts2會根據其設置的值匹配跳轉
對於json通常狀況下不多用到,可是在處理ext的時候會用到這個屬性類型,這個地方也是常常被忽略的。
最後感受仍是應該查一下文檔給野豬看看,嘿嘿:
Redirect Action Result
<package name="public" extends="struts-default"> <action name="login" class="..."> <!-- Redirect to another namespace --> <result type="redirect-action"> <param name="actionName">dashboard</param> <param name="namespace">/secure</param> </result> </action> </package> <package name="secure" extends="struts-default" namespace="/secure"> <-- Redirect to an action in the same namespace --> <action name="dashboard" class="..."> <result>dashboard.jsp</result> <result name="error" type="redirect-action">error</result> </action> <action name="error" class="..."> <result>error.jsp</result> </action> </package> <package name="passingRequestParameters" extends="struts-default" namespace="/passingRequestParameters"> <-- Pass parameters (reportType, width and height) --> <!-- The redirect-action url generated will be : /genReport/generateReport.action?reportType=pie&width=100&height=100 --> <action name="gatherReportInfo" class="..."> <result name="showReportResult" type="redirect-action"> <param name="actionName">generateReport</param> <param name="namespace">/genReport</param> <param name="reportType">pie</param> <param name="width">100</param> <param name="height">100</param> </result> </action> </package>
Redirect Result
<result name="success" type="redirect"> <param name="location">foo.jsp</param> <param name="parse">false</param> </result>
<package name="passingRequestParameters" extends="struts-default" namespace="/passingRequestParameters"> <-- Pass parameters (reportType, width and height) --> <!-- The redirect-action url generated will be : /genReport/generateReport.jsp?reportType=pie&width=100&height=100 --> <action name="gatherReportInfo" class="..."> <result name="showReportResult" type="redirect"> <param name="location">generateReport.jsp</param> <param name="namespace">/genReport</param> <param name="reportType">pie</param> <param name="width">100</param> <param name="height">100</param> </result> </action> </package>
這下感受怎麼樣了?野豬!多看看文檔!
最後,又看了一眼result的默認參數:
<result name="success" type="dispatcher"> <param name="location">/ThankYou.jsp</param> </result>
呵呵……這還比較滿意!吃飯去!野豬!