SpringMVC配置

1.目錄圖如下

2.Eclipse里new一個Dynamic Web Project,如下圖所示:

點擊下一步,下一步,出現(xiàn)如下圖所示,勾選紅框里的,點擊finish。

3.添加jar包,Spring的jar包得依賴這個包,為了方便我直接把Spring的所有jar包都復制到這個目錄下,然后再build paths。

4.新建需要的包和文件、jsp

5.配置web.xml

圖:

配置:

"http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://java.sun.com/xml/ns/javaee"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

id="WebApp_ID"version="3.0">

springDispatcherServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:springmvc.xml

1

springDispatcherServlet

/

6.配置springmvc.xml,在src目錄下右鍵new,other,出現(xiàn)如下圖所示:

點擊紅框,next,出現(xiàn)如下圖所示:

輸入springmvc.xml,點擊next,

出現(xiàn)如下圖所示:

勾選紅框里的,點擊finish。

然后就是配置springmvc.xml.

?xmlversion="1.0"encoding="UTF-8"?>

"http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd

http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.3.xsd">

"com.dake">

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

"prefix"value="/WEB-INF/views/">

"suffix"value=".jsp">

標注1是要掃描的包的路徑:

標注2直接負責過去就行

7.測試,views目錄下新建一個success.jsp,配置

8.修改index.jsp

9在com.dake包下新建Test類:

配置如下:

10.運行:點擊hello

出現(xiàn):


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容