前言

本案例是在idea编辑器下,maven管理项目的前提下。

步骤

1.新建maven项目

2.配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="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_2_5.xsd" version="2.5"> <!-- //前端控制器;springmvc的入口,*.do所有以.do结尾的请求都会被拦截-->
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <!-- &lt;!&ndash; Map all requests to the DispatcherServlet for handling &ndash;&gt;-->
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <servlet>
<servlet-name>Myservlet</servlet-name>
<servlet-class>com.test01.Dome01</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>Myservlet</servlet-name>
<url-pattern>/test.do</url-pattern>
</servlet-mapping> </web-app>

3.配置spring-mvc.xml


这里有一点小小的说明,<mvc:default-servlet-handler/>这个标签是springmvc 3.0以后用来访问静态资源的;

<context:component-scan base-package="com" />这个注解就是扫描包了;所有扫描的类都可以交由spring管理

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <mvc:annotation-driven/>
<mvc:default-servlet-handler/>
<context:component-scan base-package="com.controller" /> <!-- 对静态资源文件的访问 restful--> <!-- -->
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes" value="text/html;charset=UTF-8"></property>
</bean>
</mvc:message-converters> </mvc:annotation-driven>
<!-- 配置SpringMVC的视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean> </beans>

4.添加springmvc的maven依赖;只需要一个即可

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

5.需要将tomcat里的jar包添加进来

点击ok即可

6.编写测试类

下面是目录结构和测试类的代码

7.如果只是需要依赖注入和页面跳转的功能,其实以上的配置就足够了;需要扫描管理的包,可以直接在spring-mvc.xml中配置

下面附上tomcat配置启动图;如果运行报错的时候可以参考一下

o(* ̄︶ ̄*)oo(* ̄︶ ̄*)oo(* ̄︶ ̄*)o    不能多写了。需求任务下来了。要去敲代码了。忙完了再接着写下一篇接着整合。。。

springmvc基础使用配置的更多相关文章

  1. spring 5.x 系列第2篇 —— springmvc基础 (代码配置方式)

    文章目录 一.搭建hello spring工程 1.1 项目搭建 1.2 相关注解说明 二.配置自定义拦截器 三.全局异常处理 四.参数绑定 4.1 参数绑定 4.2 关于日期格式转换的三种方法 五. ...

  2. spring 5.x 系列第1篇 —— springmvc基础 (xml配置方式)

    文章目录 一.搭建hello spring工程 1.1 项目搭建 1.2 相关配置讲解 二.配置自定义拦截器 三.全局异常处理 四.参数绑定 4.1 参数绑定 4.2 关于日期格式转换的三种方法 五. ...

  3. SpringMVC基础配置及使用

    SpringMVC基础配置及使用 SpringMVC:1.SpringMVC和Spring的关系:    软件开发的三层架构: web层[表示层.表现层]---->Service层----> ...

  4. SpringMVC基础入门

    一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 1 2 3 4 5 6 ...

  5. SpringMVC框架入门配置 IDEA下搭建Maven项目

    初衷:本人初学SpringMVC的时候遇到各种稀奇古怪的问题,网上各种技术论坛上的帖子又参差不齐,难以一步到位达到配置好的效果,这里我将我配置的总结写到这里供大家初学SpringMVC的同僚们共同学习 ...

  6. SpringMVC基础入门,创建一个HelloWorld程序

    ref:http://www.admin10000.com/document/6436.html 一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要 ...

  7. 关于什么是SpringMVC,和SpringMVC基于xml配置、注解配置、纯注解配置

    首先我们先要了解一下,什么是SpringMVC? SpringMVC是Spring框架内置的MVC的实现.SpringMVC就是一个Spring内置的MVC子框架,也就是说SpringMVC的相关包都 ...

  8. java框架之SpringBoot(5)-SpringMVC的自动配置

    本篇文章内容详细可参考官方文档第 29 节. SpringMVC介绍 SpringBoot 非常适合 Web 应用程序开发.可以使用嵌入式 Tomcat,Jetty,Undertow 或 Netty ...

  9. SpringMVC基础01——SpringMVC的知识结构体系

    1.前言 目前在各大互联网公司使用最热门的技术莫过于SpringBoot以及在其基础之上的SpringCloud,然而学习这些技术的基础在于学好Spring和SpringMVC,准确来说SpringM ...

随机推荐

  1. POJ 2115

    ax=b (mod n) 该方程有解的充要条件为 gcd(a,n) | b ,即 b% gcd(a,n)==0 令d=gcd(a,n) 有该方程的 最小整数解为 x = e (mod n/d) 其中e ...

  2. python PIL实现图片合成

    在项目中需要将两张图片合在一起.遇到两种情况,一种就是两张非透明图片的合成, 一种是涉及到透明png的合成. 相关API见 http://pillow.readthedocs.io/en/latest ...

  3. Python-计算机硬件基础

    预习计算机硬件基础1,CPU/内存.硬盘2,存储器 什么是编程语言什么是编程编程的目的运行程序的三大核心硬件重要:运行程序,硬件的工作过程 ------------------------------ ...

  4. Linux文件系统深度讨论【转】

      本文旨在对Linux文件系统概念高级工作方式进行的讨论,不是对特定文件系统类型(如EXT4)如何工作的低级描述,也不是对文件系统命令的教程. 每台通用计算机都需要将各种类型的数据存储在硬盘驱动器( ...

  5. 【MySql】delete用法

    delete 语句用于删除表中的数据, 基本用法为: delete from 表名称 where 删除条件; 以下是在表 students 中的实例: 删除 id 为 3 的行: delete fro ...

  6. Confluence 6 数据库表-杂项(Miscellaneous)

    这些部分是一些其他的表格,这些表格有必要在这里提及下能帮你更好的了解系统. os_propertyentry 有关实体和属性相关的特性. bandana 所有的持久层.这个表格包含的的内容有用户设置和 ...

  7. Confluence 6 整合到其他数据库

    这个文档描述了如何整合你的 Confluence 数据库从你已经存在的数据库上到其他的数据库.这个指南被用来指导你从使用评估数据库转移到使用生产数据库. 大数据量需要第三方的数据库整合工具. 本页面对 ...

  8. LoadRunner监控window系统各项指标详解

    一.监控系统时,需要监控的项 System 系统 Processor 处理器 Memory 内存 PhysicalDisk 磁盘 Server 服务器 二.指标详解 (一). PhysicalDisk ...

  9. Python基础知识之大杂烩

    一.range 和 xrange 的区别 xrange 与 range 基本上都是在循环的时候用,两者的用法完全相同.所不同的是xrange生成的是一个生成器,而range生成的是一个list对象. ...

  10. Win#password;;processon #clone;;disassemble;;source find

    1.密码学思维导图 源地址:https://www.processon.com/view/5a61d825e4b0c090524f5b8b 在这之前给大家分享 如何在 processon上搜索公开克隆 ...