strut2.0 与 hibernate spring 的整合
[color=red]1.在 web.xml 文件中的配置[/color]
[quote]<!--应用上下文 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
[color=green]/WEB-INF/applicationContext.xml[/color]</param-value>
[color=blue]<!-- 如果applicationContext.xml在src目录下存放,绿色位置应该为
classpath:applicationContext.xml-->[/color]
</context-param>
<!-- spring的监听器,以便在启动时就自动加载spring的配置 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 使用filter加载struts.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-pattern>/*</url-pattern>
</filter-mapping> [/quote]
[color=red]2.在src下添加一个 struts.xml文件 [/color]
[quote]<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.i18n.encoding" value="GBK" />
[color=red]<!-- 将action托管给spring --> [/color]
<constant name="struts.objectFactory" value="spring" />
<include file="struts-default.xml" />
[color=red]<!--strut2上传文件保存的地址-->[/color]
<constant name="struts.multipart.saveDir" value="c:\"></constant>
<package name="struts2" extends="struts-default">
<action name="index" class="goods">
<interceptor-ref name="defaultStack" />
<result name="index">/jsp/index.jsp</result>
</action>
</package>
</struts> [/quote]
[color=red]3.在spring 配置文件中配置[/color]
[quote] <bean name="goods" class="com.accp.ssh.action.GoodsAction"
scope="prototype">
</bean> [/quote]
[color=red]1.在 web.xml 文件中的配置[/color]
[quote]<!--应用上下文 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
[color=green]/WEB-INF/applicationContext.xml[/color]</param-value>
[color=blue]<!-- 如果applicationContext.xml在src目录下存放,绿色位置应该为
classpath:applicationContext.xml-->[/color]
</context-param>
<!-- spring的监听器,以便在启动时就自动加载spring的配置 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 使用filter加载struts.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-pattern>/*</url-pattern>
</filter-mapping> [/quote]
[color=red]2.在src下添加一个 struts.xml文件 [/color]
[quote]<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.i18n.encoding" value="GBK" />
[color=red]<!-- 将action托管给spring --> [/color]
<constant name="struts.objectFactory" value="spring" />
<include file="struts-default.xml" />
[color=red]<!--strut2上传文件保存的地址-->[/color]
<constant name="struts.multipart.saveDir" value="c:\"></constant>
<package name="struts2" extends="struts-default">
<action name="index" class="goods">
<interceptor-ref name="defaultStack" />
<result name="index">/jsp/index.jsp</result>
</action>
</package>
</struts> [/quote]
[color=red]3.在spring 配置文件中配置[/color]
[quote] <bean name="goods" class="com.accp.ssh.action.GoodsAction"
scope="prototype">
</bean> [/quote]