mveerman
mveerman

Reputation: 40867

In struts2 how do I redirect to a jsp with additional parameters

I have an interceptor that needs to abort an action and redirect to a new page. Currently, it's returning a string like "go_to_foo". That's working fine, but I also want to send an additional parameter to the action. I've tried to configure that result in struts.xml like:

<global-results>
            ...
            <result name="go_to_foo">
                <param name="location">foo.jsp</param>
                <param name="testing">mark</param>
            </result>
</global-results>

I'm getting the following exception: Caught OgnlException while setting property 'testing' on type 'org.apache.struts2.dispatcher.ServletDispatcherResult'. I'm wondering if this is due to the fact that the Request object doesn't know about any 'testing' parameter.

Alternatively, I'm also wondering if it's possible for an Interceptor to add/modify the request's parameters before returning the string "go_to_foo" such that they are still available in foo.jsp. If something like this is possible perhaps I don't need what's above.

I hope that was clear enough.

Thanks, Mark

Upvotes: 1

Views: 6040

Answers (2)

Steven Benitez
Steven Benitez

Reputation: 11055

The <param/> tag is for setting parameters on the result, not for adding query string parameters to the redirect.

e.g., <param name="testing">mark</param> is trying to call setTesting("mark") on the ServletRedirectResult class. There is no such method.

Try: <param name="location">foo.jsp?testing=mark</param>

Also, do you really need to redirect? Why not just add the needed parameter to the action context and continue on?

Upvotes: 2

Liviu T.
Liviu T.

Reputation: 23664

You forgot the type=redirect attribute

<result name="go_to_foo" type="redirect">
     <param name="location">foo.jsp</param>
     <param name="testing">mark</param>
</result>

to access the value use

<s:property value="#parameters.testing" />

or

${parameters.testing[0]}

Upvotes: 3

Related Questions