美文网首页
SpringMVC配置

SpringMVC配置

作者: PowerWudake | 来源:发表于2017-01-05 12:14 被阅读0次

1.目录图如下

2.Eclipse里new一个Dynamic Web Project,如下图所示:

点击下一步,下一步,出现如下图所示,勾选红框里的,点击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,出现如下图所示:

点击红框,next,出现如下图所示:

输入springmvc.xml,点击next,

出现如下图所示:

勾选红框里的,点击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

出现:


相关文章

网友评论

      本文标题:SpringMVC配置

      本文链接:https://www.haomeiwen.com/subject/lwczvttx.html