------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------

咱们这个案例做什么?

  就是用处理器代替Servlet处理请求

开发步骤:

  1.引入jar包

<!--单元测试的依赖  ctrl+shif+/-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2..RELEASE</version>
</dependency> <!--引入beans节点-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.2..RELEASE</version>
</dependency> <dependency>
<groupId> org.aspectj</groupId >
<artifactId> aspectjweaver</artifactId >
<version> 1.8.</version>
</dependency> <!--SpringWebMVC-->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2..RELEASE</version>
</dependency> <!--ServletAPI-->
<dependency>
<groupId>javaee</groupId>
<artifactId>javaee-api</artifactId>
<version></version>
</dependency> <dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency> <!--SpringWeb-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2..RELEASE</version>
</dependency>

  2.具体的开发流程

    

    此处标红的表示需要配置的,未标红的表示本身就有默认值,可以无需配置springmvc也能执行

  3.准备一个index.jsp页面

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<body>
<h2>Hello SpringMVC!今天揭开你的新面纱</h2>
</body>
</html>

  4.创建一个类FirstController

package cn.dawn.day01;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; /**
* Created by Dawn on 2018/3/19.
*/
//处理器
public class FirstController implements Controller {
/**
* handleRequest 处理请求
* @param httpServletRequest
* @param httpServletResponse
* @return
* @throws Exception
*/
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
ModelAndView me=new ModelAndView();
me.setViewName("index.jsp");
return me;
}
}

  5.配置大配置文件ApplicationContext-day01.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!--配置bean处理器-->
<bean id="/first" class="cn.dawn.day01.FirstController"></bean>
</beans>

  6.web.xml配置前端控制器

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app>
<display-name>Archetype Created Web Application</display-name>
<!--中央调度器-->
<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-day01.xml</param-value>
</init-param>
<load-on-startup></load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> </web-app>

  配置完成,打开tomcat服务器中,在网页url中访问http://localhost:8080/项目名/first(根据你自己的配置来)

SSM-SpringMVC-02:SpringMVC最简单的小案例的更多相关文章

  1. SpringMVC 02: SpringMVC响应get和post请求 + 5种获取前端数据的方式

    响应get和post请求 SpringMVC中使用@RequestMapping注解完成对get请求和post请求的响应 项目结构和配置文件与SpringMVC博客集中的"SpringMVC ...

  2. Turtle绘图——python简单上手小案例

    Turtle绘图 Turtle模块提供了在二维平面上移动的环境. Turtle可以实现位置.航向和各种可能的状态和动作. import turtle as tu roo = tu.Turtle() # ...

  3. MyBatis小案例完善增强

    https://blog.csdn.net/techbirds_bao/article/details/9233599 上链接为一个不错的Mybatis进阶博客 当你把握时间,时间与你为伍. 将上一个 ...

  4. 使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(二)(代码篇)

    这篇是上一篇的延续: 用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(一) 源代码在github上可以下载,地址:https://github.com/guoxia ...

  5. 简单易学的SSM(Spring+SpringMVC+MyBatis)整合

    SSM(Spring+SpringMVC+MyBatis)的整合: 具体执行过程:1.用户在页面向后台发送一个请求 2.请求由DispatcherServlet 前端控制器拦截交给SpringMVC管 ...

  6. 使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(三)(错误整理篇)

    使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(一) 使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(二) 以上两篇已经把流 ...

  7. 使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(一)

    梳理下使用spring+springMVC+mybatis 整合后的一个简单实例:输入用户的 ID,之后显示用户的信息(此次由于篇幅问题,会分几次进行说明,此次是工程的创建,逆向生成文件以及这个简单查 ...

  8. SSM,即Spring+SpringMVC+MyBatis三个开源框架的整合框架集。

    SSM(Spring+SpringMVC+MyBatis)框架集由Spring.SpringMVC.MyBatis三个开源框架整合而成,常作为数据源较简单的web项目的框架. 其中spring是一个轻 ...

  9. Maven+SSM框架(Spring+SpringMVC+MyBatis) - Hello World(转发)

    [JSP]Maven+SSM框架(Spring+SpringMVC+MyBatis) - Hello World 来源:http://blog.csdn.net/zhshulin/article/de ...

随机推荐

  1. [Err] ORA-00923: FROM keyword not found where expected 与rownum

    关于oracle的nownum 如果我想查询表的全部信息,并且前面加上行号,sql如下 select  ROWNUM,* from tableA 会报下面的错误 [Err] ORA-00923: FR ...

  2. 【OpenCV学习】Kmean均值聚类对图片进行减色处理

            #include <cv.h> #include <highgui.h> #include <iostream> #define MAX_CLUST ...

  3. C# 添加、读取Word脚注尾注

    脚注和尾注是对文本的补充说明.脚注一般位于页面的底部,可以作为文档某处内容的注释:尾注一般位于文档的末尾,列出引文 的出处等.在本示例中将介绍如何来添加或删除Word脚注. 工具使用:Free Spi ...

  4. TCP浅谈为什么3次握手

    <计算机网络>中的例子是这样的,"已失效的连接请求报文段"的产生在这样一种情况:客户发出的第一个连接请求报文段并没有丢失,而是在某个网络结点长时间的滞留了,以致延误到连 ...

  5. .Net C# 串口 Serialort safe handle has been closed 问题的解决

    最近在一个平台上使用SerialPort类开发程序时,发现程序在使用SerialPort类时会异常退出,而且诡异的是,就算把所有操作串口的代码都放在try{}catch{}块中也无法捕获这个异常.最终 ...

  6. Django之admin的使用和源码剖析

    admin组件使用 Django 提供了基于 web 的管理工具. Django 自动管理工具是 django.contrib 的一部分.你可以在项目的 settings.py 中的 INSTALLE ...

  7. 前端技术之_CSS详解第三天

    前端技术之_CSS详解第三天 二.权重问题深入 2.1 同一个标签,携带了多个类名,有冲突: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...

  8. jQuery插件之-----弹性运动

    <!doctype html><html><head><meta charset="utf-8"><title>弹性运动 ...

  9. 排序算法入门之希尔排序(java实现)

    希尔排序是对插入排序的改进.插入排序是前面元素已经有序了,移动元素是一个一个一次往后移动,当插入的元素比前面排好序的所有元素都小时,则需要将前面所有元素都往后移动.希尔排序有了自己的增量,可以理解为插 ...

  10. Qt与FFmpeg联合开发指南(三)——编码(1):代码流程演示

    前两讲演示了基本的解码流程和简单功能封装,今天我们开始学习编码.编码就是封装音视频流的过程,在整个编码教程中,我会首先在一个函数中演示完成的编码流程,再解释其中存在的问题.下一讲我们会将编码功能进行封 ...