Form validation in Struts2

前端 未结 1 318
梦如初夏
梦如初夏 2021-01-21 13:30

Page contains form which looks like below.

1) If I insert to form validate=\"true\", then after page load this form submit request to mail action (at this poin

相关标签:
1条回答
  • 2021-01-21 13:55

    INPUT is one of the predefined results made available by Struts2;

    Basically, if your Action sends parameters that are incorrect (conversion errors, like if you send a "abc" to an Integer Action variable), or that don't pass the validation, the Workflow Interceptor return the INPUT result and follow the path specified in the struts configuration for that Action.

    Your problem is that you have not defined any INPUT result for your Actions, while you always should.

    You can also set a global input result as a fallback, but be careful with that... generally, the page you want to go in case of an INPUT is the same from where the request has been sent.

    In case of an INPUT result, your Action method (eg. execute()) is not executed, so if you load common data in that method, like select boxes content, it won't be available anymore.

    Read this answers to fully understand what this implies and how to make it work:

    • How do we repopulate controls when validation fails

    • Detailed Workflow of the INPUT result processing

    0 讨论(0)
提交回复
热议问题