在struts2中如何重定向到带有附加参数的jsp
我有一个拦截器需要中止操作并重定向到新页面。目前,它返回一个类似“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您忘记了
type=redirect
属性来访问值 use
或
You forgot the
type=redirect
attributeto access the value use
or
标记用于在结果上设置参数,而不是用于将查询字符串参数添加到重定向。
例如,
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 callsetTesting("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?