开发者

Where does Struts a controller redirect when a form validation fails?

Does it redirect to the value in input attribut开发者_JS百科e 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. )


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜