天天看點

eclipse搭建SSH(二)——Struts+Spring

接上一篇,本篇主要介紹在Struts基礎上加載spring。

搭建環境

eclipse

jdk-8u121-windows-x64

Tomcat8.0

Struts-2.5.26

Spring-5.3.8

1、導入spring jar包

在lib路徑下導入spring相關的jar包,注意,将lib路徑下的jar包全部導入到項目Java Build Path路徑之下。

eclipse搭建SSH(二)——Struts+Spring

2、建立applicationContext.xml檔案

在src目錄下建立applicationContext.xml檔案。

eclipse搭建SSH(二)——Struts+Spring

3、修改struts.xml

這裡需要注意,action的class屬性值必須與applicationContext.xml檔案中bean的id一緻。

eclipse搭建SSH(二)——Struts+Spring

 4、修改web.xml

添加spring監聽,因為項目預設讀取WEB-INF目錄下的配置檔案,而我們将spring的配置檔案applicationContext.xml建立在src目錄中,是以,這裡添加<context-param>選項,指定讀取類檔案路徑。

eclipse搭建SSH(二)——Struts+Spring

5、啟動Tomcat

eclipse搭建SSH(二)——Struts+Spring

正确輸入使用者名001,密碼123456,跳轉至result頁面,表示搭建Struts+spring成功。

eclipse搭建SSH(二)——Struts+Spring

繼續閱讀