前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >web项目常见错误和解决方案

web项目常见错误和解决方案

作者头像
剽悍一小兔
发布2018-05-17 15:01:27
9240
发布2018-05-17 15:01:27
举报
01、 The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

2016-10-10 今天遇到一个奇怪的错误,关于Springmvc的,我明明在Controller方法中写了@ResponseBody,返回一个Map,结果报了406错误。

Paste_Image.png

结果发现,少了一个jar包:

Paste_Image.png

加上去就没事了。

pom.xml

代码语言:javascript
复制
<dependency>  
    <groupId>com.fasterxml.jackson.core</groupId>  
    <artifactId>jackson-core</artifactId>  
    <version>2.1.0</version>  
</dependency>  
<dependency>  
    <groupId>com.fasterxml.jackson.core</groupId>  
    <artifactId>jackson-databind</artifactId>  
    <version>2.1.0</version>  
</dependency>  
<dependency>  
    <groupId>com.fasterxml.jackson.core</groupId>  
    <artifactId>jackson-annotations</artifactId>  
    <version>2.1.0</version>  
</dependency>  

如果还不能解决,就检查在web.xml中配置的spring拦截后缀,不要使用.html后缀!

02、 The method getServletContext() is undefined for the type HttpServletRequest

2016-10-11 这个问题也挺奇怪的,我记得以前都是这么写:

//获取服务器的路径 String dirPath = request.getServletContext().getRealPath("/");

今天,这段代码竟然报错了,说这个方法未定义,我TM也是无语了。

原来,高版本的servlet已经不支持这个方法了。代替方案为:

String dirPath = request.getSession().getServletContext().getRealPath("/");

OK,完美解决。

02、 SpringMVC项目,什么都配好了,可就是进不了Controller,控制台也不报错,页面显示400 ?

原因: 多半是因为数据绑定错误了,比如你用了@PathVariable,@RequestParam等,而前台没有传进来对应的值。那么就会出现这种情况,而且控制台不报错。

也可能是绑定JavaBean的时候,前台传过来一个String类型的日期,而JavaBean中的日期是Date格式的,它转不了,那么也可能会出现这个情况。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016.10.10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 01、 The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.
  • 02、 The method getServletContext() is undefined for the type HttpServletRequest
  • 02、 SpringMVC项目,什么都配好了,可就是进不了Controller,控制台也不报错,页面显示400 ?
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档