2016-10-10 今天遇到一个奇怪的错误,关于Springmvc的,我明明在Controller方法中写了@ResponseBody,返回一个Map,结果报了406错误。
Paste_Image.png
结果发现,少了一个jar包:
Paste_Image.png
加上去就没事了。
pom.xml
<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后缀!
2016-10-11 这个问题也挺奇怪的,我记得以前都是这么写:
//获取服务器的路径 String dirPath = request.getServletContext().getRealPath("/");
今天,这段代码竟然报错了,说这个方法未定义,我TM也是无语了。
原来,高版本的servlet已经不支持这个方法了。代替方案为:
String dirPath = request.getSession().getServletContext().getRealPath("/");
OK,完美解决。
原因: 多半是因为数据绑定错误了,比如你用了@PathVariable,@RequestParam等,而前台没有传进来对应的值。那么就会出现这种情况,而且控制台不报错。
也可能是绑定JavaBean的时候,前台传过来一个String类型的日期,而JavaBean中的日期是Date格式的,它转不了,那么也可能会出现这个情况。