亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問板塊 發(fā)新帖
查看: 3150 | 回復(fù): 0
打印 上一主題 下一主題

Spring Struts整合方案匯總小結(jié) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2010-01-14 11:09 |只看該作者 |倒序?yàn)g覽



Spring和Struts整合的方案有很多種,整理如下:
第一種 Listener方式
將Spring服務(wù)作為web容器的Listener,隨web服務(wù)器啟動(dòng)而啟動(dòng)
   1、需要在web.xml中配置
Java代碼

  •    
  • class>org.springframework.web.context.ContextLoaderListenerclass>   
  •   
    org.springframework.web.context.ContextLoaderListener
       2、然后在Struts的action中通過
    Java代碼

  • ServletContext sc = this.getServlet().getServletContext();   
  • WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sc);   
  • ctx.getBean("xxx");  ServletContext sc = this.getServlet().getServletContext();
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sc);
    ctx.getBean("xxx");
    完成托管Bean的獲取。
    第二種 Load on Startup Servlet方式
    將Spring服務(wù)作為web容器的load on startup Servlet,隨web服務(wù)器啟動(dòng)而啟動(dòng),這種方式和第一種基本是一樣的,只是spring加載的時(shí)間會(huì)比第一種晚一些,servlet2.3標(biāo)準(zhǔn),listener的加載早于startup servlet的加載
       1、這種方式需要在web.xml中配置
    Java代碼

  •    
  • contextLoader   
  • class>org.springframework.web.context.ContextLoaderServletclass>   
  • 1   
  •   
    contextLoader
    org.springframework.web.context.ContextLoaderServlet
    1
       2、這種整合方案,獲取bean的方法,和第一種方式相同
    第三種 Struts Plugin+Spring DelegatingRequestProcessor方式
    前兩種方式,都沒有將struts的action納入spring管理,接下來的要說的兩種方式比較類似,放在一起說明,都是可以將Struts的action納入到Spring管理的方式。
       1、通過Struts的Plugin方式,在應(yīng)用啟動(dòng)時(shí)加載Spring容器,既然是Struts的Plugin,當(dāng)然是在struts-xxx.xml文件中進(jìn)行配置,增加如下Plugin:
    Java代碼

  • "org.springframework.web.struts.ContextLoaderPlugIn">   
  • "contextConfigLocation" value="/WEB-INF/applicationContext.xml,/WEB-INF/applicationContext_xxx.xml"/>   
  •   
       2、Struts是通過ActionServlet處理請(qǐng)求的,而代碼實(shí)現(xiàn)上是通過RequestProcessor進(jìn)行處理的,通過Spring的RequestProcessor子類-DelegatingRequestProcessor,可以替代原有的Struts請(qǐng)求處理方式,從而轉(zhuǎn)到Spring容器中進(jìn)行處理。因此需要更改原有的Struts RequestProcessor行為,使用Spring自己的DelegatingRequestProcessor,這需要在struts-xxx.xml中配置,增加如下配置:
    Java代碼

  • "org.springframework.web.struts.DelegatingRequestProcessor">  
       3、經(jīng)過上面的配置,現(xiàn)在struts的action已經(jīng)交給spring來管理了,spring的DelegatingRequestProcessor會(huì)處理web請(qǐng)求,將請(qǐng)求轉(zhuǎn)發(fā)給struts-xxx.xml中定義的action,而這些action又是通過spring管理的,因此原來的struts配置文件中的action配置:...中的type就可以省略了,改成...,而type的設(shè)置則放到spring的配置文件中,上文中指定了兩個(gè)spring配置文件/WEB-INF/applicationContext.xml,/WEB-INF/applicationContext_xxx.xml,我們?cè)谄渲幸粋(gè)文件中加入:
    Java代碼

  • "/login" class="com.soar.loginAction" singleton="false">   
  • "xx">   
  •    just a String property   
  •    
  •    
  •   

       just a String property


    這和對(duì)待普通的bean沒有什么區(qū)別了,但是名字是struts配置文件中指定的path指定的值"/login",設(shè)置singleton="false"是每請(qǐng)求一次,生成一個(gè)action(和struts1默認(rèn)策略不同)
    這樣就完成了spring與struts的整合以及spring管理action


    本文來自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u2/69320/showart_2148617.html
  • 您需要登錄后才可以回帖 登錄 | 注冊(cè)

    本版積分規(guī)則 發(fā)表回復(fù)

      

    北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年舉報(bào)專區(qū)
    中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
    感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP