Scope= "Prototype" should be configured when spring manages STRUTS2 action

Source: Internet
Author: User
Spring By default scope is a single case pattern, that is, scope= "Singleton", which creates only one action object, that is, each access is the same action object and the data is unsafe. And struts2 is required to each access requires a different action, scope= "prototype" can guarantee this requirement, when there is a request to create an Action object.
<span style= "Font-weight:normal;" ><span style= "FONT-SIZE:14PX;" ><!--Configure action-->
<bean id= "testaction" class= "com.lmk.test.TestAction"  scope= "prototype" >
	<!--action injection  <property name= "T" ref= "T"/>-->
</bean></span></span>




The more common point is that if the use of a single example mode, then Struts2 from the foreground data, after processing, once again entered the page, the previous submission of data will be retained.
For example:
Query system users: When the user name a query after the first request, and then enter the query page, the system will retain the previous query conditions.


Of course, you can also set scope= "session" and avoid concurrent problems with action in the web, creating only one bean for the current user until
Session disappears. In this case, the bean is stateful to the current user. The benefit is to create an instance of the bean less and have a
Improvement of the point of performance
Application Scenario:
1. Prototype should be used in most cases
2. If the user is not many, and frequent operation (frequently use action), hardware general, you can consider session, may also improve a little bit of performance.



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.