Struts2的数据串问题

在使用spring加struts2的架构时,当访问用户多的时候老出现数据串的情况啊!最后加scope="prototype"避免struts中Action的线程安全问题

spring 默认scope 是单例模式
这样只会创建一个Action对象
每次访问都是同一个Action对象,数据不安全
struts2 是要求 每次次访问 都对应不同的Action
scope="prototype" 可以保证 当有请求的时候 都创建一个Action对象

代码如下:

@Scope("prototype")
@Namespace("/test")
public class TestAction extends ActionSupport {
....
}

  @Scope("prototype")

导入的类为:

import org.springframework.context.annotation.Scope;

猜你喜欢

转载自liuna718-163-com.iteye.com/blog/1888690