1.目錄圖如下
2.Eclipse里new一個(gè)Dynamic Web Project,如下圖所示:
點(diǎn)擊下一步季率,下一步,出現(xiàn)如下圖所示描沟,勾選紅框里的飒泻,點(diǎn)擊finish。
3.添加jar包吏廉,Spring的jar包得依賴這個(gè)包泞遗,為了方便我直接把Spring的所有jar包都復(fù)制到這個(gè)目錄下,然后再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)如下圖所示:
點(diǎn)擊紅框,next,出現(xiàn)如下圖所示:
輸入springmvc.xml,點(diǎn)擊next,
出現(xiàn)如下圖所示:
勾選紅框里的生巡,點(diǎ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">
標(biāo)注1是要掃描的包的路徑:
標(biāo)注2直接負(fù)責(zé)過去就行
7.測(cè)試,views目錄下新建一個(gè)success.jsp孤荣,配置
8.修改index.jsp
9在com.dake包下新建Test類:
配置如下:
10.運(yùn)行:點(diǎn)擊hello
出現(xiàn):