开发者

Struts 2 - How to map a wildcard-matched method to an exception?

I'm working with Struts2. Here's a snippet of my struts.xml file:

<action name="*test" class="fend.config.TestAction" method="{1}">
            <exception-mapping result="fail" exception="java.lang.UnsupportedOperationException"/>
            <result name开发者_JS百科="success">/registerCrisis.jsp</result>
            <result name="dummy">/dummy.jsp</result>
            <result name="fail">error.jsp</result>
            <interceptor-ref name="configStack"/>
        </action>

When I run the application like: http://localhost:8080/appContext/viewtest.action struts calls the view method in the TestAction class. I the view method I put code that generates a java.lang.UnsupportedOperationException just for testing purpose.

What I intended was to redirect to the result named fail, so that error.jsp is showned. But it's not redirecting to the page. What I've missed?

Thank you.


You can create another action under your exist action , this may allow the rest of paths (errors path) to redirect another action , this may allow the rest of paths (errors path) to redirect another page.

<action name="*test" class="fend.config.TestAction" method="{1}">

        <result name="success">/registerCrisis.jsp</result>
        <result name="dummy">/dummy.jsp</result>
        <result name="fail">error.jsp</result>
        <interceptor-ref name="configStack"/>
    </action>

<!-- SOLUTION, ADD THIS-->

    <action name="*" method="myErrorMethod" class="fend.config.TestAction">
        <result type="redirectAction">
            <param name="namespace">/myErrorPath</param>
            <param name="actionName">myErrorMethodtest</param><!--*test (if your error method has wildcard) -->
        </result>
    </action>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜