歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Struts2 action之間相互跳轉傳遞參數

Struts2 action之間相互跳轉傳遞參數

日期:2017/3/1 10:03:22   编辑:Linux編程

今天遇到一個問題,在Webwork 2.2裡面給一個Action的result傳多個參數:
原先配置如下

<action name="blahblahAction" class="blahAction" method="blah">
<result name="success" type="redirect">/some.action?field1=${field1}&field2=${field2}</result>
</action>

運行時候出現如下提示:
The reference to entity "field2" must end with the ';' delimiter.
我本以為是OGNL的問題,四處搜尋,不得其解……看了DTD也沒有發現問題。
後來修改過程中突然發現原來是SAX解析器出錯,我這才想到可能是XML的問題。
經過再三查詢得到解決方案:
使用"&amp;"代替"&",原理和HTML中的轉義相同,我居然忘記了XML的語法規范,慚愧。
配置如下:

<action name="blahblahAction" class="blahAction" method="blah">
<result name="success" type="redirect">/some.action?field1=${field1}&amp;field2=${field2}</result>

下邊是另外一個人的:

今天在用struts2在做項目時候,從一個action我想跳轉到另一個action,並且呢得帶上值。說說我的做法吧,首先你得在你的第一個action中這個id必須要有set、get方法。
跳轉時你的struts.xml:
(方法一):
<result name="topic" type="redirect">/topicAction!findTopics.do?topicId=${topicId}</result>
(方法二):
<result name="topic" type="redirect-action">
<param name="actionName">findTopics</param>
<param name="topicId">${topicId}</param>
</result>

如果是多個參數的話,繼續再加幾個<param>就行了,對於(方法一)如果是多個參數的怎麼辦? <result name="topic" type="redirect">/topicAction!findTopics.do?topicId=${topicId}&amp;elementId=${elementId}</result>
這不就行了。

Copyright © Linux教程網 All Rights Reserved