今天在开发中遇到了一个问题,控制层使用的是SpringMVC框架。

    @RequestMapping("historyDetail")
private String History(ModelMap model,LedMsgTextInfo condition){
LedMsgTextInfo ledMsgTextInfo;
Long id = condition.getId();
ledMsgTextInfo = ledMsgTextService.getById(id);
List<DeviceLedInfo> ledDeviceList = DeviceLedService.queryLedDeviceList(null);
for(DeviceLedInfo ledInfo:ledDeviceList){
String DeviceCode = ledInfo.getDeviceCode();
if(ledMsgTextInfo.getDeviceCode().equals(DeviceCode)){
ledMsgTextInfo.setDeviceName(ledInfo.getDeviceName());
}
}
model.put("ledDeviceList", ledMsgTextInfo);
return "jtyd/historyDetail";
}

在进行页面跳转时,出现了异常:HTTP Status 500 - Could not resolve view with name ‘jtyd/historyDetail’ in servlet with name ‘dispatcher’

查询网上资料后,有两种类型的错误说明,一种是页面跳转,一种是json返回。

页面跳转:

出现这种异常可能是由于返回值不对,本例中返回值实际上应该是:jtyd/HistoryDetail。仅仅是一个字母的差别。

json返回:

出现这种异常可能是因为在配置文件中配置了:

 <property name="defaultContentType" value="text/html" />

想要纠正就需要改为:

<property name="defaultContentType" value="application/json" />

或者在每一个适配器(请求的方法)上面加上@ResponseBody注解。

个人认为第二种情况出现的错误比较少见,常见的还是第一种情况,即写错了返回值。所以在书写代码的时候一定要注意避免出现书写错误,细心就行。

备注: 
关于第二种配置的问题,个人开发过程中还没有尝试在配置文件中添加返回头的配置,都是通过书写@ResponseBody注解来解决异步请求的返回值处理问题的。

遇到一个比较详细的案例:http://blog.csdn.net/abc360200314/article/details/22862727 
出的问题是一样的,但是解决方式不同,目前还没有去看jar包的问题。

05-11 12:56