Copyright Notice: This article for Bo Master original article, without Bo Master permission not reproduced.
Problem Description: Submit the form for the first time. If a data does not conform to the rule, an error message appears. Submit again, the last error message displayed does not disappear, and an additional error message is identical. Submit several times, and you'll see a few more identical error messages.
At first, the problem was also thought to be the fault of spring and struts integration, consulted a lot of data, and learned about the check rules of struts:
--that is, validation check first, if not, jump directly to the input page, no longer enter the action, while populating the Fielderror field, the page can be accessed fielderror to get the error prompt.
And the Struts2 action is not a singleton pattern, and an object is generated each time it is submitted, so you must include the scope= "prototype" attribute in spring's settings for the action. That
In spring's configuration file, the action configuration is modified by adding scope= "prototype" (scope= "prototype" creates a new action object when the object of that type is requested. If the scope =prototype is not configured, it will not create a new action when it is added, and he will keep the last logged-on information. )
Spring default scope is a singleton mode, so that only one action object is created, each access is the same action object, and the data is unsafe. In comparison, STRUTS2 requires that each access corresponds to a different action
The scope= "prototype" (multi-case mode) ensures that an action object is created when a request is made
1 <!--configuration Registeraction--2 class= "Com.blog.action.Register" scope= " Prototype "> <!--Add scope=" prototype "-3 <property name=" UserService ">4 <ref bean= "UserService"/> 5 </property>6 7 </bean>
By the way, attach the configuration in the Struts.xml:
1<?xml version= "1.0" encoding= "UTF-8"?>2 3<!DOCTYPE Struts public4"-//apache software foundation//dtd Struts Configuration 2.0//en"5"Http://struts.apache.org/dtds/struts-2.0.dtd" >6 7<struts>8<constant name= "struts.i18n.encoding" value= "gb2312" ></constant>9< PackageName= "Struts2"extends= "Struts-default" >Ten<action name= "Register"class= "Registeraction" > <!--registeraction is a reference to the above ID registeraction, which is the integration of STRUTS2 and spring One<result name= "Success" >/success.jsp</result> A<result name= "Error" >/error.jsp</result> -<result name= "Input" >/register.jsp</result> -</action> the</ Package> -</struts>
Verify that information repeats multiple times using the STRUTS2 validation framework