springmvc基础使用配置
前言
本案例是在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> <!-- <!– Map all requests to the DispatcherServlet for handling –>-->
<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基础使用配置的更多相关文章
- spring 5.x 系列第2篇 —— springmvc基础 (代码配置方式)
文章目录 一.搭建hello spring工程 1.1 项目搭建 1.2 相关注解说明 二.配置自定义拦截器 三.全局异常处理 四.参数绑定 4.1 参数绑定 4.2 关于日期格式转换的三种方法 五. ...
- spring 5.x 系列第1篇 —— springmvc基础 (xml配置方式)
文章目录 一.搭建hello spring工程 1.1 项目搭建 1.2 相关配置讲解 二.配置自定义拦截器 三.全局异常处理 四.参数绑定 4.1 参数绑定 4.2 关于日期格式转换的三种方法 五. ...
- SpringMVC基础配置及使用
SpringMVC基础配置及使用 SpringMVC:1.SpringMVC和Spring的关系: 软件开发的三层架构: web层[表示层.表现层]---->Service层----> ...
- SpringMVC基础入门
一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 1 2 3 4 5 6 ...
- SpringMVC框架入门配置 IDEA下搭建Maven项目
初衷:本人初学SpringMVC的时候遇到各种稀奇古怪的问题,网上各种技术论坛上的帖子又参差不齐,难以一步到位达到配置好的效果,这里我将我配置的总结写到这里供大家初学SpringMVC的同僚们共同学习 ...
- SpringMVC基础入门,创建一个HelloWorld程序
ref:http://www.admin10000.com/document/6436.html 一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要 ...
- 关于什么是SpringMVC,和SpringMVC基于xml配置、注解配置、纯注解配置
首先我们先要了解一下,什么是SpringMVC? SpringMVC是Spring框架内置的MVC的实现.SpringMVC就是一个Spring内置的MVC子框架,也就是说SpringMVC的相关包都 ...
- java框架之SpringBoot(5)-SpringMVC的自动配置
本篇文章内容详细可参考官方文档第 29 节. SpringMVC介绍 SpringBoot 非常适合 Web 应用程序开发.可以使用嵌入式 Tomcat,Jetty,Undertow 或 Netty ...
- SpringMVC基础01——SpringMVC的知识结构体系
1.前言 目前在各大互联网公司使用最热门的技术莫过于SpringBoot以及在其基础之上的SpringCloud,然而学习这些技术的基础在于学好Spring和SpringMVC,准确来说SpringM ...
随机推荐
- 使用Gitblit 在Windows上部署Git Server
Windows平台下Git服务器搭建 首先要下载Java JDK,安装完成后设置环境变量,先把java环境配好,接下来才是下面的gitblit.关于java环境配置请看上一篇文章 gitblit下载 ...
- ajax 上传文件给webapi(带basic认证)
$('#btnupload').on('click', function () { var fd = new FormData(); ]; fd.append("report_id" ...
- importlib模块
importlib模块 import importlib根据这个字符串来导入这个模块的 a=importlib.import_module('xx.oo')print(a.Person())里面可以传 ...
- linux 过滤内存使用率并于计划任务结合来自动清理内存缓存
过滤出内存使用率并进行判断 #!/bin/bash echo "###cleand free_cache script########" #memory usage mem_pus ...
- swiper轮播图(逆向自动切换类似于无限循环)
swiper插件轮播图,默认的轮播循序是会从右向左,第一张,第二张,第三张,然后肉眼可见是的从第三张从左到右倒回第一张,这样就会有些视觉体验不高, ,不过还是能够用swiper本身的特性更改成无限循环 ...
- Oracle12c 的安装教程图解(安装系统:windows 2008R2)
Oracle12c 的安装教程图解(安装系统:windows 2008R2) 第一节 安装和下载路径 1 官方下载路径: http://www.oracle.com/cn/products/dat ...
- 自执行匿名函数: (function() { /* code */ })();
1,常见格式:(function() { /* code */ })(); 2,解释:包围函数(function(){})的第一对括号向脚本返回未命名的函数,随后一对空括号立即执行返回的未命名函数,括 ...
- vuejs中使用echarts
<style scoped> .content { /*自行添加样式即可*/ } #main { /*需要制定具体高度,以px为单位*/ height: 400px; } </sty ...
- Python1 简介及安装、基础
Python介绍 Python是面向对象,高级语言,解释,动态和多用途编程语言.Python易于学习,而且功能强大,功能多样的脚本语言使其对应用程序开发具有吸引力. Python的语法和动态类型具有其 ...
- Python学习【第2篇】:Python数据结构
Python数据结构 1.数字类型 2.字符串 3.列表 4.元组 5.字典 6.集合