SoFunction
Updated on 2025-03-08

struts2 spring integration fieldError problem


question:

The verification framework is used. After the jsp page verification fails once, no matter whether the input is correct or not, the exception page cannot be redirected.


reason:

When spring creates an action object, the default is singleton. The so-called singleton refers to spring generating only one object for an IOC container. In my verification, I did not request submissions, and I used an action object, so all error information was stored in the map (fieldError message) and not cleared.


Solution:

So in order to clear the error message in the map every time I requested, I needed to recreate an object for each request using action. When configuring the bean corresponding to the action in the applicationContext-*.xml file, the property scope="prototype" should be attached. This achieves the goal. The problem was solved.