Sturts2 action multiple examples and Singleton, sturts2action

Source: Internet
Author: User

Sturts2 action multiple examples and Singleton, sturts2action

The Action of struts 2 is a multi-instance, not a Singleton, that is, an Action object is generated for each request. The reason is: struts 2 Action contains data. For example, the data you enter on the page will be contained in the member variable of the Action. If the Action is a single instance, the data will affect each other in a multi-threaded environment. For example, the data entered by others will be visible to you. Therefore, the Action of Struts2 is in the Multi-sample mode.

If the problem occurs, can the struts2 action be changed to the singleton mode? When I used spring to generate an action, I found that all the generated actions were single-instance. Isn't this making my program run out of bugs by default? Information submitted by the previous user. If the next user does not fill in the information, the information entered by the previous user is actually gone.

 

Background:

1) Struts2 generates an Action instance for each browser for processing.

2) by default, beans managed by Spring Ioc containers are single instances.

First of all, from the perspective of data security, we should ensure that the Action is multi-instance so that data problems do not occur. However, if some actions, such as only admin, can be operated, or some actions, are shared by the whole site to improve performance, then the singleton mode can be used.

But fortunately, Spring bean can set its scope for each, so the above problem is not a problem. If multiple examples are used, set scope = "prototype" during spring action bean configuration. Okay, the problem ends here.

Related Article

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.