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.