从过滤器类调用struts 2动作
我在我的 struts 2 应用程序中添加了一个过滤器。我正在使用这个过滤器来检查 cookie 值。如果找到适当的 cookie,那么我想将用户重定向到主页而不是正常的登录页面。 因此,为了显示主页,我想调用与主页关联的 struts 2 操作。 我尝试从过滤器调用 homepage.execute() 方法,但这不会显示与主页关联的结果(jsp 页面)。 请建议我一些从 Fiter 类调用主页操作的方法。
I added a filter in my struts 2 application. I am using this filter to check cookie values. If appropriate cookie is found then i want to redirect user to home page rather than normal login page.
So for displaying home page I want to call struts 2 action associated with home page.
I tried calling homepage.execute() method from filter, but this does not display the result(jsp page) associated with home page.
Please suggest me some way to call homepage action from fiter class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道你的要求是什么,但通常使用 Struts 2 拦截器是一个更好的主意。
无论如何,您不能直接从 Java 调用操作,因为它不会触发框架内容。相反,您应该考虑重定向到操作的映射网址(例如:response.sendRedirect("http://your_host_name/your_action_name.action"))
I don't know what your requirements are, but usually using a Struts 2 interceptor is a better idea.
Anyway you can't invoke action directly from Java because it would not trigger the framework stuff. Instead you should consider to redirect to the mapped url of the action (for example:
response.sendRedirect("http://your_host_name/your_action_name.action") )