为了账号安全,请及时绑定邮箱和手机立即绑定

java中在tomcat获取绝对路径的问题

使用SpsringMVC,使用restEasy调试,controller请求设置如下:
Java代码 收藏代码
@RequestMapping(value="/list",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<EditTimeout> list(){
List<EditTimeout> list = editImpl.selectAll();
return list;
}

请求,debug跟踪list是返回值没有问题,但是前台页面报如下错误:
Java代码 收藏代码
Response Status: 406 (Not Acceptable)

Response RAW返回值如下,(前半部分)
Xml代码 收藏代码
HTTP GET http://127.0.0.1:8080/onlineLibrary/rest/system/editTimeout/list
Host: 127.0.0.1:8080

406 Not Acceptable
Date: Sat, 17 Aug 2013 11:01:07 GMT
Server: Apache-Coyote/1.1
Content-Length: 1067
Content-Type: text/html;charset=utf-8
<html><head><title>Apache Tomcat/7.0.34 - Error report</title><style>

后台提示错误:
Java代码 收藏代码
2013-08-17 19:01:03,116 DEBUG org.springframework.web.servlet.DispatcherServlet -Last-Modified value for [/onlineLibrary/rest/system/editTimeout/list] is: -1
2013-08-17 19:01:07,606 DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
2013-08-17 19:01:07,680 DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
2013-08-17 19:01:07,681 DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

引起的原因:
由于设置了@ResponseBody,要把对象转换成json格式,缺少转换依赖的jar包,故此错。
解决办法:
加入依赖的jar,jackson-core-asl-1.9.12.jar,jackson-mapper-asl-1.9.12.jar问题解决。

点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
JAVA开发工程师
手记
粉丝
168
获赞与收藏
3550

关注作者,订阅最新文章

阅读免费教程

感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消