`
anysky131
  • 浏览: 172502 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Spring+Hibernate+Struts2整合笔记二

    博客分类:
  • SSH
阅读更多

二、 Spring+Struts2整合:

1spring配置在web.xml文件中的上下文监听器:

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/applicationContext*.xml</param-value>

</context-param>

<listener>

<listener-class>org.springframwork.web.content.ContextLoaderListener</listener-class>

</listener>

2struts2配置在web.xml文件中的过滤器:

<filter>

<filter-name>struts2</filter-name>

<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>

</filter>

<filter-mapping>

<filter-name>struts2</filter-name>

<url-patter>/*</url-patter>

</filter-mapping>

3、设置struts.xml文件,就可以使用springIOC来管理strutsAction

<content name="struts.objectFactory" value="spring" >

4、第三步设置后,以后在struts.xml 文件中配置一个action时,它的class就不是一个类了,而是在applicationContext.xml文件中定义过的类的ID,struts.xml文件中就只需要引用定义好的类的id 就可以了。

然后特别要注意的一个问题:action是一个请求就是一个action对象,而在spring中则不是的,它是自动分配类的实例的,是使用的单态模式来生产类的实例的,不符合action,因此在applicationContext.xml文件中定义每个action时,都要在类后加上:

scope="prototype" 属性

来标明才不会出错。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics