Struts2 url问题
我正在编写一个 struts2 应用程序,要访问用户必须登录的系统。我的操作工作正常,系统工作正常,但操作返回“成功”后,它转发到“welcome.jsp”页面,但网址以“login.action”结尾。为了刷新页面,我需要 url 以“welcome.jsp”结尾。如何在不使用 javascript 手动更改 url 的情况下实现此目的?非常感谢。
这是我的 struts.xml 文件中的操作标签...
<action name="login" method="authenticate" class="LoginAction">
<result name="success">welcome.jsp</result>
<result name="error">login.jsp</result>
</action>
I am writing a struts2 application and to access the system the users has to login. The action I have works correctly and the system works fine but after the action returns "success" it forwards to the "welcome.jsp" page but the url ends with "login.action" . For the purpose of refreshing the page, I need the url to end with "welcome.jsp". How can I achieve this without using javascript to change the url manually? Thank you very much.
This is the action tag in my struts.xml file...
<action name="login" method="authenticate" class="LoginAction">
<result name="success">welcome.jsp</result>
<result name="error">login.jsp</result>
</action>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确设计的基于操作的应用程序中的每个 URL 都应该指向调度 servlet/filter(即在您的情况下以 .action 结尾),而不是直接指向 JSP。这就是 Struts 等基于操作的框架的操作模式的全部内容。
为了做你想做的事情,你不应该在登录成功后转发到welcome.jsp。您应该重定向到welcome.action 操作,然后该操作将转发到welcome.jsp。请参阅http://struts.apache.org/2.0.14/ docs/redirect-action-result.html 了解详细信息。并参见http://en.wikipedia.org/wiki/Post/Redirect/Get 有关 Post/Redirect/Get 模式的说明。
Every URL in a properly designed action-based application should point to the dispatching servlet/filter (i.e. end with .action in your case), and never directly to a JSP. That's what the action pattern of action-based frameworks like Struts is all about.
To do what you want to do, you should not forward to the welcome.jsp after the login is sucessful. You should instead redirect to the welcome.action action, which would then forward to the welcome.jsp. See http://struts.apache.org/2.0.14/docs/redirect-action-result.html for details. And see http://en.wikipedia.org/wiki/Post/Redirect/Get for explanations on the Post/Redirect/Get pattern.