Verify that information repeats multiple times using the STRUTS2 validation framework

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.