Struts中配置的result

2021-07-13 13:46:54 字數 3952 閱讀 4350

在struts.xml配置檔案中遇到了param,有點迷糊,上網查了查……似乎明白些了

$/jeecms

loginframeinput

這裡的action 是log,他包含了登陸和退出,當系統在登入的時候就直接返回$就可以了;在退出的時候需要返回到登陸頁面,所以退出的時候是**到 action的,**到action肯定要告訴系統**到那個action,該action的namespace是什麼,名字是什麼,就是通過param 該屬性老告知struts2的;當然param還有其他用法,不過一般就用這個就差不多了,綜上得出:

param標籤主要用於為其他標籤提供引數,例如bean和include標籤。

param引數設定:

name:可選屬性,指定設定引數名稱

value:可選屬性,指定引數的值

id:可選屬性,指定該元素引用id

看到這,野豬似乎感覺清楚了許多,嘿嘿……

下面還搜到了一些資訊,等野豬不是很清楚的時候再看看吧……

chain  

用來處理action鏈,被跳轉的action中仍能獲取上個頁面的值,如request資訊。       

com.opensymphony.xwork2.actionchainresult       

dispatcher

用來轉向頁面,通常處理jsp       

org.apache.struts2.dispatcher.servletdispatcherresult    

freemaker

處理freemarker模板       

控制特殊http行為的結果型別       

處理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區別

一、使用redirect需要字尾名 使用redirect-action不需要字尾名 

二、type="redirect" 的值可以轉到其它命名空間下的action,而redirect-action只能轉到同一命名空下的 action,因此它可以省略.action的字尾直接寫action的名稱。

如:viewtask.action

viewtask

附:redirect-action 傳遞引數

<

action

name

="enterpreinfo"

class

="preinfobusinessaction"

method

="enterpreinfosub"

>

<

result

name

="success"

type

="redirect-action"

>

showpreinfo?preinfo.order_number

=$&preinfo.company_name

=$   

result

>

<

result

name

="error"

type

="redirect"

>

<

param

name

="location"

>

/error.jsp

param

>

result

>

action

>

因為使用了redirect-action,所以要注意不能將 showpreinf?preinfo.order_number=$寫成 showpreinf.action?preinfo.order_number=$

其中${}為el表示式,獲取action:enterpreinfo中屬性的值;在這個配置檔案裡,多個引數的連線符使用了"&",但xml的語法規範,應該使用"&"代替"&",原理和html中的轉義相同,開始沒有注意,在struts分析配置檔案時,總是報出這樣的錯誤:

json   一般很容易忽略的乙個地方(在ext中非常有用)

示例

view plain

copy to clipboard

print?

"struts2"

extends=

"json-default"

namespace

="/"

>  

"login"

class

="loginaction"

method=

"login"

>  

"json"

>  

"includeproperties"

>success,result

"main"

class

="loginaction"

method=

"main"

>  

"main"

>/index.jsp

view plain

copy to clipboard

print?

private

boolean

success  = 

true

;  private

string result = 

"main.action"

;  //getter和setter方法略

以上的success和result互相對應到了
view plain

copy to clipboard

print?

<

param

name

="includeproperties"

>

success,result

param

>

struts2會根據其設定的值匹配跳轉
對於json一般情況下很少用到,但是在處理ext的時候會用到這個屬性型別,這個地方也是經常被忽略的。

struts2零配置中的常量配置

value true value true name value truts.convention.action.disablejarscanning 設定是否從jar包搜尋action類 適合於將action達成jar包的人使用,預設為true,不需要,可以自定義關閉 struts.convent...

struts1中配置應用

列表收集id集合時,在formbean中放乙個string selectflag 陣列,這時提交時formbean會自動收集 function deleteuser if flag if window.confirm 確認刪除嗎?直接將值放到request中,前台用el或標籤顯示出來 beanuti...

struts中採用註解配置Action

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!需要匯入struts2 convention plugin的jar包 action 省略getters和setters parentpackage xystruts default namespace login public class logi...