在struts2中如何重定向到带有附加参数的jsp

发布于 2024-10-06 15:35:27 字数 663 浏览 0 评论 0原文

我有一个拦截器需要中止操作并重定向到新页面。目前,它返回一个类似“go_to_foo”的字符串。这工作正常,但我还想向操作发送一个附加参数。我尝试在 struts.xml 中配置该结果,如下所示:

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

我收到以下异常:在类型“org.apache.struts2.dispatcher.ServletDispatcherResult”上设置属性“testing”时捕获 OgnlException。我想知道这是否是因为请求对象不知道任何“测试”参数。

另外,我还想知道拦截器是否可以在返回字符串“go_to_foo”之前添加/修改请求的参数,以便它们在 foo.jsp 中仍然可用。如果这样的事情是可能的,也许我不需要上面的内容。

我希望这已经足够清楚了。

谢谢, 标记

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泅渡 2024-10-13 15:35:27

您忘记了 type=redirect 属性

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

来访问值 use

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

${parameters.testing[0]}

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]}
£噩梦荏苒 2024-10-13 15:35:27

标记用于在结果上设置参数,而不是用于将查询字符串参数添加到重定向。

例如,mark 尝试在 ServletRedirectResult 类上调用 setTesting("mark")。没有这样的方法。

尝试: foo.jsp?testing=mark

另外,您真的需要重定向吗?为什么不将所需的参数添加到操作上下文中并继续?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文