views:

216

answers:

1

Does it redirect to the value in input attribute in the action element of struts-config file? How can we set the flag redirect="true" for the forward when validation fails? ( So that the url of page being redirected to, is shown in the browser instead of html:form action url. )

+2  A: 

If there are any validation errors, the "execute" method of the action class will not get called; instead the control will go back to the “input” file until the form has no ActionErrors associated with it. So your statement is correct, you get redirected to the value in the “input” attribute in the “action” element of “struts-config.xml”, or more exactly, you are forwarded there.

At this point you could forward to a JSP containing something like this in it:

<%response.sendRedirect(strWhereTo);%>

Or you could specify an action (*.do or what extension you are using) for the "input" attribute, where this action could be an instance of org.apache.struts.action.RedirectingActionForward which redirects to your JSP (it’s been a while since I used Struts, so I’m not so sure about this second method :D).

Hope this helps. Cheers!

dpb