且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Struts2验证无法正常工作,未显示验证错误消息

更新时间:2023-09-11 23:03:22

阅读 INPUT结果的工作原理,然后已经放弃了ModelDriven设计模式,除了问题之外,该模式不会给您的编程体验带来任何好处,因为它们很容易隐藏在拦截器堆栈的中间 a>,请注意:

After having read how the INPUT result works and having abandoned the ModelDriven design pattern that adds nothing to your programming experience except problems, that might easily hide themselves in the middle of the Interceptor Stack, note that:

  • redirect是重定向到外部URL或非Action URL时使用的结果,而redirectAction重定向到Action时应使用;
  • 重定向时,将创建一个新请求,因此旧参数(包括操作错误以及消息和字段错误)将丢失.
  • redirect is the result to use when redirecting to external URLs or non-Action URLs, while redirectAction should be used when redirecting to an Action;
  • when redirecting, a new request is created, and hence the old parameters (including action errors and messages and field errors) are lost.

为防止这种情况,如果您想继续使用PRG模式(并因此使用重定向),可以使用 MessageStore拦截器,它将跨重定向为您存储和检索消息;只需定义一个包含它的拦截器堆栈即可解决您的问题.

To prevent that, if you want to keep using the PRG pattern (and hence the redirection), you can use the MessageStore Interceptor that will store and retrieve the messages for you across the redirections; just define an interceptor stack that contains it, and it will solve your problem.

或者像文档中示例中的那样进行一次

Or do it once like in the example from the documentation.