spring管理Struts2的action时应配置scope="prototype"
2016-08-31 15:08
447 查看
spring 默认情况下scope 是单例模式,即scope="singleton",这样只会创建一个Action对象,即每次访问都是同一个Action对象,数据不安全。而struts2 是要求 每次访问 都要求对应不同的Action, scope="prototype" 就可以保证这个要求, 当有请求的时候 都创建一个Action对象。
<span style="font-weight: normal;"><span style="font-size:14px;"><!-- 配置action --> <bean id="testAction" class="com.lmk.test.TestAction" scope="prototype"> <!-- action注入 <property name="t" ref="t" />--> </bean></span></span>
再讲得通俗一点就是如果采用单例模式,那么Struts2从前台得到的数据,经过处理结束后,再次进入该页面时,前一次提交的数据还是会被保留下来。
例如:
查询系统中的用户:当用户名a查询第一次请求结束后,再进入查询页面时,系统会保留前一次的查询条件。
当然,也可以设置scope="session",也能避免web中action的并发问题,只为当前用户创建一次bean,直至
session消失。在这种情况下,对当前用户而言,bean是有状态的。好处就是少创建bean的实例,有那么一
点点性能的提升
应用场景:
1. 多数情况下应使用prototype
2. 若用户不多,且频繁操作(频繁使用action),硬件一般,可以考虑session,兴许还能提升一点点性能。
相关文章推荐
- struts+spring action应配置为scope="prototype"
- struts+spring action应配置为scope="prototype"
- struts+spring action应配置为scope="prototype"
- struts+spring action应配置为scope="prototype"
- struts+spring action应配置为scope="prototype"
- struts+spring action应配置为scope="prototype"
- struts2.0中spring配置文件中action的属性 scope="prototype"
- struts+spring action应配置为scope="prototype"
- struts+spring action应配置为scope="prototype"
- struts+spring action应配置为scope="prototype"
- struts2.0中spring配置文件中action的属性 scope="prototype" .
- struts+spring action应配置为scope="prototype"
- struts2.0中spring配置文件中action的属性 scope="prototype"
- spring action scope="prototype"
- spring 管理action实例 scope="session"
- Spring配置<bean>时加scope="prototype"的原因
- (上节)Spring+JDBC+Struts;实现图片上传;配置的属性默认dbc用单例模式,action一定要scope=“prototype”
- Spring注解@Scope("prototype") Spring在Action上面注解@Scope("prototype")
- sping+struts2中配置Action的bean中scope="prototype"的作用
- sping+struts2中配置Action的bean中scope="prototype"的作用