天天看點

struts2.xml中使用chain和redirectAction這兩個類型結果(type-result)時,報檢查錯誤(validation)

當在struts.xml中使用chain和redirectAction這兩個類型結果的時候,會報檢查錯誤!

Multiple annotations found at this line:

    - Undefined actionnamespace

     parameter

    - Undefined actionName parameter

相信不少朋友會被這個錯誤折騰的很難受吧,現在說下解決方案,在百度和google上搜了很久,國外網站也看了下,半天都沒找到解決方法,後來無意中在apache的網站上看到了struts2 chain的使用說明,仔細讀了一下,就想到了一個辦法,或許可以解決,于是就測試了一下,發現問題完全解決了,現在來說下一我的解決方法。

chain結果類型有4個屬性,分别是:

    actionName (default) - the name of the action that will be chained to

    namespace - used to determine which namespace the Action is in that we're chaining. If namespace is null, this defaults to the current namespace

    method - used to specify another method on target action to be invoked. If null, this defaults to execute method

    skipActions - (optional) the list of comma separated action names for the actions that could be chained to

其中actionName和namespace是必不可少的,否則就會報錯。是以我在項目中就寫成如下形式:

<package name="struts" extends="struts-default" namespace="/bg">

       <action name="login" class="loginAction">

            <result type="chain">

                <param name="actionName">index</param>

                <param name="namespace">/bg</param>

            </result>

        </action>

</package>

但是這麼寫就有一個問題,我的項目比較簡單,不想使用命名空間,于是我就想怎麼解決這個問題呢,在看官方文檔的時候我發現這麼一句話:

A root namespace ("/") is also supported. The root is the namespace when a request directly under the context path is received. As with other namespaces, it will fall back to the default ("") namespace if a local action is not found.

于是我就想,用"/"代替"/bg"不就可以解決問題了麼。然後就把代碼寫成如下形式

<package name="struts" extends="struts-default" namespace="/">

                <param name="namespace">/</param>

好了說到這裡我想大家也都明白了該怎麼解決chain和redirectAction這兩個類型結果(type-result)報檢查錯誤(validation)的問題了吧!

有多的不對的地方還請大家多多指教!!

淡定的部落格

繼續閱讀