Spring 和struts1 整合的三種方式

2021-06-06 05:03:07 字數 1390 閱讀 9128

spring 和 struts1 整合的三種方式。

1,使用spring 的 actionsupport 

2, 使用spring 的 delegatingrequestprocessor 類。

3,全權委託。

無論用那種方法來整合第一步就是要為struts來裝載spring的應用環境。 就是在 struts 中加入乙個外掛程式。

struts-config.xml中

1,使用spring的actionsupport .

這中配置方式同直接在web.xml檔案配置差別不大。注意:action繼承自 org.springframework.web.struts.actionsupport 使得struts和spring耦合在一起。

但實現了表示層和業務邏輯層的解耦(logindao dao = (logindao) ctx.getbean("logindao"))。

2,使用spring 的 delegatingrequestprocessor 類

delegatingrequestprocessor  繼承自 org.apache.struts.action.requestprocessor 並覆蓋了裡面的方法。

sturts-config.xml  中   通過 來替代

org.apache.struts.action.requestprocessor 的請求處理。

public class loginaction extends action 

public logindao getdao()

這裡 name="/login" 與struts 中的path匹配 

class="com.cao.struts.action.loginaction" 與struts 中的type匹配

3,全權委託:

action 的建立和物件的依賴注入全部由ioc容器來完成。 使用spring的delegatingacionproxy來幫助實現**的工作 

org.springframework.web.struts.delegatingactiongproxy繼承於org.apache.struts.action.action .

type="org.springframework.web.struts.delegatingactionproxy" >

不同之處

1, 中 type指向的是spring 的**類

2, 去掉struts-config.xml中

三種整和方式中我們優先選用 全權委託的方式。

理由:1,第一種使得過多的耦合了spring和action .

2,requestprocessor類已經被** 如果要再實現自己的實現方式(如:編碼處理)怕有點麻煩。

struts1整合ajax技術

1.寫乙個繼承actionservlet的類a。在該類a中重寫httpservlet的service方法,然後呼叫actionservlet中的process方法,然後從requst中得到要返回給前台的值value,如果不為空,則用response.getwriter print value 2.修...

spring整合struts1三種方式

spring和struts整合方式 1 最簡單方式 struts 來裝載spring 的應用環境。就是在struts 中加入乙個外掛程式。struts config.xml 中 幾乎與 struts 無關了,相當於為整合專案加入 spring 支援,將 的配置放在 web.xml 中了 contex...

struts1和struts2的區別

1 struts1必須要繼承乙個抽象基類 dispatchaction struts2 只要是乙個有execute方法的pojo就可以,不用一定繼承 但是,struts2一般繼承乙個com.opensymphany.xwork2.actionsupport來實現一些常用方法。3 表示式 struts...