how to redirect struts2 action to a url after validation?
I have a action with a url creation like this
if (this.sequence.equals("") ) {
action= "input";
} else {url = "/files/" + testHTML.getName();
action= "redirect";
}
开发者_StackOverflow return action;
in my struts.xml my action is declarated has
<interceptor-ref name="completeStack"/>
<interceptor-ref name="execAndWait">
<param name="delaySleepInterval">500</param>
</interceptor-ref>
<result name="wait">testwait.jsp</result>
<result name="input">test.jsp</result>
<result name="redirect" type="redirect">${url}</result>
</action>
When I launch the application, the url is created but there are no redirection to this new page but to the test.jsp page and I have the validation error message that appear. Anybody have some idea?
Your original code example looks correct. Here are a few things to check:
- Does your action have a
getUrl()
method? The${url}
part of the result relies on that method to get theurl
property. - Have you verified that the correct result is returned in each case? e.g., 'redirect' in the else block and 'input' otherwise.
if you are using validate method and if there is validation errors struts return result name="input". In your case put redirect in
<result name="input" type="redirect">${url}</result>
精彩评论