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>
开发者_C百科</action>
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.
精彩评论