11.SSH整合

由于自己学习的版本比较落后,这里就不总结了

  在我这个版本整合的过程中的几点问题:

  1.在web.xml的配置过程中:
    

<!-- 如果使用的是load获取数据,在jsp页面申请取得数据时才真正的执行sql,而此时session已经关闭 -->
  <!-- 需要加上 OpenSessionInViewFilter 这个拦截器,用于延长session在jsp调用完后再关闭,另外需要写在 struts 拦截器之前 -->
  <!-- 原因:Filter顺序—先进后出,写在 struts之前,先经过openSessionInViewFilter,由其管理session,struts拦截完后,openSessionInViewFilter再决定 关闭session的时间-->
  <!-- 另外:这个过滤器会对事务产生影响,如果方法没有加上事务边界,那么 openSessionInViewFilter 自动将该方法变为 只读 方法,所以需要在配置 文件中 指定 事务边界-->
  <filter>
      <filter-name>openSessionInViewFilter</filter-name>
      <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  </filter>
  <filter-mapping>
      <filter-name>openSessionInViewFilter</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>

  

  2.注:struts2 Spring 整合之后,Action 的 生成方式有两种

第一种:<action name="user" class="com.bjsxt.registration.action.UserAction">

这种方式 struts 创建Actionstruts创建的Action有几个特点:

1.不需要写   @Resource   Action一产生的时候呢,会到Spring容器里面去找它要注入的内容   servicedao等)(只要有 get set 法,默认就会按照 byName的方式 自动装配到Action中)

 2.不需要写  @Component,因为,Action struts管理的,写了只会在Spring容器中多出来个bean而已

3.不需要写 @Scope(prototype)默认设置就是每次访问都创建Action

 

第二种:<action name="user" class="u>  使用action标签中 class属性配合  @Componentu

这种方式可以由 spring 创建Actionspring创建的Action特点:

0.Action中需使用  @Componentu),来生成 Action 这个bean

1.可以 指定 注入 bean的 具体名字 ,即可以使用 @Resourcename=””;

2.需要 使用@Scope(prototype)不要忘记因为默认的应该是 ‘单例的’

    

注:struts2 Spring 整合之后,Action 的 生成方式有两种

第一种:<action name="user" class="com.bjsxt.registration.action.UserAction">

这种方式 struts 创建Actionstruts创建的Action有几个特点:

1.不需要写   @Resource   Action一产生的时候呢,会到Spring容器里面去找它要注入的内容   servicedao等)(只要有 get set 法,默认就会按照 byName的方式 自动装配到Action中)

 2.不需要写  @Component,因为,Action struts管理的,写了只会在Spring容器中多出来个bean而已

3.不需要写 @Scope(prototype)默认设置就是每次访问都创建Action

 

第二种:<action name="user" class="u>  使用action标签中 class属性配合  @Componentu

这种方式可以由 spring 创建Actionspring创建的Action特点:

0.Action中需使用  @Componentu),来生成 Action 这个bean

1.可以 指定 注入 bean的 具体名字 ,即可以使用 @Resourcename=””;

2.需要 使用@Scope(prototype)不要忘记因为默认的应该是 ‘单例的’

原文地址:https://www.cnblogs.com/xuzekun/p/7400276.html