ygizard
ygizard

Reputation: 51

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";

    }
      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?

Upvotes: 2

Views: 2585

Answers (2)

Steven Benitez
Steven Benitez

Reputation: 11055

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 the url property.
  • Have you verified that the correct result is returned in each case? e.g., 'redirect' in the else block and 'input' otherwise.

Upvotes: 1

Zemzela
Zemzela

Reputation: 3080

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>

Upvotes: 0

Related Questions