Spring-mvc的搭建详解

1.下载jar包。

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.13.RELEASE</version>
</dependency>


<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.13.RELEASE</version>
</dependency>

1在web.xml中配置前端控制器


<servlet>
<!--配置前端控制器-->
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--初始化参数-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<!--这句话什么意思:只要tomcat一起动,就将servlet对象创建好放入内存了-->
<load-on-startup>1</load-on-startup>
</servlet>
<!--静态资源的方式-->
<servlet-mapping>

<servlet-name>springmvc</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>


<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2017/8/14
Time: 9:52
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h2>加油加油${uname}</h2>
<img src="${pageContext.request.contextPath}/img/004.jpg">
</body>
</html>
 <!--方式二:-->
<mvc:default-servlet-handler/>
<!--方式三:-->
<mvc:resources mapping="/img/**" location="/img/"></mvc:resources>
<!--注册处理器-->
<bean id="/happy.do" class="Controller.FirstController"/>


posted @ 2017-08-14 17:05  liuzhe01  阅读(172)  评论(0编辑  收藏  举报