spring和struts整合方式
1、最簡單方式 ①
struts
來裝載spring
的應用環境。
就是在struts
中加入乙個外掛程式。
struts-config.xml
中"/>
②幾乎與
struts
無關了,相當於為整合專案加入
spring
支援,將①的配置放在
web.xml
中了<
context-param
>
<
param-name
>
contextconfiglocation
param-name
>
<
param-value
>
param-value
>
context-param
>
再加上對
spring
監聽<
listener
>
<
listener-class
>
org.springframework.web.context.contextloaderlistener
listener-class
>
listener
>
**演示
spring
的actionsupport
繼承至org.apache.struts.action.action
actionsupport
的子類可以或得
型別的全域性變數。通過
可以獲得這個變數。
這是乙個
servlet
的**:
public class loginaction extends org.
springframework
.web.struts.
actionsupport
獲得物件
中的配置
2、第二種是基於
1配置的基礎之上(①和②配置任選乙個),因為都需要裝在
spring
的應用環境容器
delegatingrequestprocessor
繼承自org.apache.struts.action.requestprocessor
並覆蓋了裡面的方法。
備註:新增
controller
在的後面
,這樣就不用不用寫
type屬性
在sturts-config.xml
中新增通過
來替代org.apache.struts.action.requestprocessor 的請求處理。
public class loginaction extends
action
public logindao getdao()
//這樣一改這行**似乎沒有必要了。
user u = new user();
u.setname(loginform.getname());
u.setpwd(loginform.getpwd());
//直接用
dao來呼叫
spring
會將這個物件例項化。
這裡的。
loginaction extends action
說明struts
每有和spring
耦合。看一下
中的配置。
name="/login"
class="com.cao.struts.action.loginaction">
這裡name="/login"
與struts
中的path
匹配class="com.cao.struts.action.loginaction" 與
struts
中的type
匹配需要說明的是,
struts
的action
裡的type
其實是個擺設,可以省略,完全可以使用
path="/login"/>,寫上是為了解決我們上面提到的「不夠直觀的」的問題
還要為loginaction
提供必要的
set***
方法。獲得
和依賴注入的工作都在
delegatingrequestprocessor
中完成。
需要說明的是,由於spring dtd
規定id不能有"/",所以我們用name定義path,並且,spring bean的name要和struts-config.xml中的path一致
3第三種也是基於
1配置的基礎之上(①和②配置任選乙個),因為都需要裝在
spring
的應用環境容器
action
的建立和物件的依賴注入全部由
ioc容器來完成。
使用spring
的delegatingacionproxy
來幫助實現**的工作
org.springframework.web.struts.delegatingactiongproxy
繼承於org.apache.struts.action.action .
全權委託的配置方式同
方式2
類似檔案的配置和
action
類的實現方式相同)。
指向的是
spring
的**類
-->
type="org.springframework.web.struts.delegatingactionproxy"
>
,可以換成在
web.xml
配置spring
容器 spring
中的配置
<?xml version="1.0" encoding="utf-8"?> xmlns="" xmlns:xsi="" xsi:schemalocation=" /spring-beans-2.5.xsd">
class="com.ssh.action.studentaction">
不同之處1,
中type
指向的是
spring
的**類2,
去掉struts-config.xml中
struts1整合ajax技術
1.寫乙個繼承actionservlet的類a。在該類a中重寫httpservlet的service方法,然後呼叫actionservlet中的process方法,然後從requst中得到要返回給前台的值value,如果不為空,則用response.getwriter print value 2.修...
Spring 和struts1 整合的三種方式
spring 和 struts1 整合的三種方式。1,使用spring 的 actionsupport 2,使用spring 的 delegatingrequestprocessor 類。3,全權委託。無論用那種方法來整合第一步就是要為struts來裝載spring的應用環境。就是在 struts ...
struts1學習筆記1
1.struts是mvc模式的經典應用。它主要是提供乙個好的控制器和一套定製的標籤庫 優點 結構層次分明,高重用性。2.開發環境搭建 建立乙個struts1的工程,匯入struts1的jar包 在web inf目錄中新增乙個struts config.xml,配置web.xml檔案中新增處理stru...