Single and multi-instance actions in SSH, SSHAction

Source: Internet
Author: User

Single and multi-instance actions in SSH, SSHAction

The Bean in Structs2 is a singleton by default. During the entire program running, each Bean has only one instance. As long as the program is running, this instance will always exist.

For an Action, a singleton is prone to problems. If the parameters submitted by the client are the same each time and the values submitted later overwrite the values submitted earlier, the problem is not very serious. However, if an optional parameter exists, for example, parameter 1 is submitted last time and parameter 2 is submitted next time. However, because it is a Singleton, the value of parameter 1 is not null at this time, it is still the value submitted last time. In this way, problems may occur easily.

The solution is to set the Action to multiple instances. An Action instance is generated for each request, so that the parameter values submitted multiple times will not affect each other. After the processing is completed, the Action instance will be automatically recycled. Compared with a single instance, multiple instances may occupy more memory, but no bug occurs.

Set Bean as a singleton:

<Bean id = "XXXAction" class = "com. XXX. action. XXXAction" scope = "singleton">

Set Bean to multiple examples:

<Bean id = "XXXAction" class = "com. XXX. action. XXXAction" scope = "prototype">

 

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.