SpringMvc 中 FrameworkServlet 覆盖 service 的有点。
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { HttpMethod httpMethod = HttpMethod.resolve(request.getMethod());
if (httpMethod == HttpMethod.PATCH || httpMethod == null) {
processRequest(request, response);
}
else {
super.service(request, response);
}
}
@Override
protected final void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected final void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

先上代码。
可以看到,最终调用了super.service,然后又覆盖了 doGet、doPost等方法。
1、为什么最后都调用了 processRequest ?
在HttpServlet中,最开始是按类型将请求分开的。但是,SpringMVC又将他们统一用 processRequest 来处理,是因为springmvc是将不同类型请求用不同的Handler来处理。
2、为什么不直接覆盖 HttpServlet,而是调用了super.service ?
现在看来结构是没有问题的。但是,如果后续扩展时想在 doPost请求之前做一些处理。。。这是,方案为覆盖 dispatcherServlet 的doPost方法, 在里边先进行一些处理,然后再调用 super.doPost。但是父类根本没调用 doPost,所以就出现问题了。这问题解决方法也很简单。但是正常逻辑 doPost 应该可以解决才对。
所以springMvc这种做法看似笨拙但是是很有必要的。
SpringMvc 中 FrameworkServlet 覆盖 service 的有点。的更多相关文章
- springmvc中request的线程安全问题
SpringMvc学习心得(四)springmvc中request的线程安全问题 标签: springspring mvc框架线程安全 2016-03-19 11:25 611人阅读 评论(1) 收藏 ...
- SpringMVC 中的Interceptor 拦截器
1.配置拦截器 在springMVC.xml配置文件增加: <mvc:interceptors> <!-- 日志拦截器 --> <mvc:interceptor> ...
- (转)SpringMVC学习(九)——SpringMVC中实现文件上传
http://blog.csdn.net/yerenyuan_pku/article/details/72511975 这一篇博文主要来总结下SpringMVC中实现文件上传的步骤.但这里我只讲单个文 ...
- 如何在springMVC 中对REST服务使用mockmvc 做测试
如何在springMVC 中对REST服务使用mockmvc 做测试 博客分类: java 基础 springMVCmockMVC单元测试 spring 集成测试中对mock 的集成实在是太棒了!但 ...
- 在Springmvc中获取properties属性
一些关键的属性一般都会拿出来作为配置,比如数据库连接等.在springmvc中也提供了获取property的类,比如@Value来获取.我接触spring很浅,基本上都是百度的问题解决方法,百度到@v ...
- 解决springmvc中文件下载功能中使用javax.servlet.ServletOutputStream out = response.getOutputStream();后运行出异常但结果正确的问题
问题描述: 在springmvc中实现文件下载功能一般都会使用javax.servlet.ServletOutputStream out = response.getOutputStream();封装 ...
- SpringMVC中使用Jcaptcha实现校验码验证
SpringMVC中使用Jcaptcha实现校验码验证:http://www.tuicool.com/articles/rMzAFj 本文将使用Jcaptcha实现校验码验证,并演示在Spring/S ...
- SpringMVC中注解和非注解方式下的映射器和适配器总结
1. 非注解方式 1.1 处理器适配器 上一节中使用的处理器适配器是:org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapte ...
- SpringMVC常用注解@Controller,@Service,@repository,@Component
SpringMVC常用注解@Controller,@Service,@repository,@Component controller层使用@controller注解 @Controller 用于标记 ...
随机推荐
- chrome插件开发学习(一)
两个不错的网址: 360chrome插件开发文档:http://open.chrome.360.cn/extension_dev/manifest.html 图灵 chrome插件开发于应用 电子书: ...
- 数组字符串json之间的相互转换
数组转字符串 var arr = [1,2,3,4,'巴德','merge']; var str = arr.join(','); console.log(str); // 1,2,3,4,巴德,me ...
- 本地Markdown文件上传到博客
本地Markdown文件上传到博客 参考:https://www.cnblogs.com/ccylhw/p/13954153.html 1.Typora 最漂亮的写作APPhttps://www.ty ...
- Ubuntu管理员手册
hostname cat /etc/hosts apt-get install iproute2 iproute2-doc ip a ps -aux
- CodeForce-811B Vladik and Complicated Book(水题)
http://codeforces.com/problemset/problem/811/B 题意: 给定一个长度为 N 不重复的数字序列,然后对其进行 M 次询问. 每次询问含L,R,X三个值,问如 ...
- NOIP初赛:完善程序做题技巧
最近写的文章好像还很多的.那么今天我们来讨论NOIP初赛的题型--完善程序.完善程序相对是比较难的题目了.全卷100分,完善程序占了大概26分,占比非常大.如果和英语考试试卷做比较,相当于首字母填空( ...
- Elasticsearch(ES)的高级搜索(DSL搜索)(下篇)
1. 概述 之前聊了Elasticsearch(ES)的高级搜索(DSL搜索)的一部分内容,今天把剩下的部分聊完. 2. 场景说明 2.1 创建索引同时创建映射 PUT http://192.168 ...
- 整理STC延时函数时遇到的玄学问题
void Delay { unsigned char i, j; i = 11; j = 190; do { while (--j); } while (--i); } void Delay { un ...
- swiper轮播高度不正常
第一次进入页面可能是网速原因,图片加载问题等吧,导致轮播图高度很大,下面出现空白, 需要加入参数 autoHeight: true, observer: true, observeParents: t ...
- 织梦 arclist调用副栏目内容解决办法
1 打开include/taglib/arclist.lib.php,找到296行: if($CrossID=='') $orwheres[] = ' arc.typeid IN ('.GetSonI ...