小结spring和struts整合的三类方式
? 整合spring和hibernate的三種方式,小結之.
?
1) 在struts中使用webapplicationcontext調用spring
??? 聲明web.xml,聲明一個contextloadlistener,讓在啟動時執(zhí)行該listener,讀spring的配置文件
??? <listener>
??<listener-class>
???org.springframework.web.context.ContextLoaderListener
??</listener-class>
?</listener>
? 再增加一個contextConfigLocation
?? <context-param>
??<param-name>contextConfigLocation</param-name>
??<param-value>/WEB-INF/applicationContext*.xml</param-value>
?</context-param>
?WebApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext(servletContext);
? UserBean userbean=(UserBean)ctx.getBean("userbean");
?
2) 將struts的action托管給spring
?????? 這也是很經常用的.用法是
??? 在struts-config.xml中,加載contextloaderplugin插件,加載spring配置
?
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />
??<plug-in
??className="org.springframework.web.struts.ContextLoaderPlugIn">
??<set-property property="contextConfigLocation"
??value="/WEB-INF/applicationContext.xml" />
??</plug-in>
? 這樣的話,把struts的action完全托管給spring了,在struts-config.xml中
??? <action path="/user/"..>,這里不需要再用class了,
但在application-context.xml中,則要有
?? <bean name="/user"..../>了.
?
3 繼承spring的actionsupport類
????? 比如
?? public class aaaa extends DispatchActionSupport
?{
??????? ......
?
????????WebApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext(servletContext);
? UserBean userbean=(UserBean)ctx.getBean("userbean");
?
?
?
?? }
???
?
???
轉載于:https://www.cnblogs.com/jackyrong/archive/2008/08/27/1278056.html
總結
以上是生活随笔為你收集整理的小结spring和struts整合的三类方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++二维数组new小结(zz)
- 下一篇: SQL Server 2008新特性——