1. 程式人生 > >Could not resolve view with name '***' in servlet with name 'dispatcher'

Could not resolve view with name '***' in servlet with name 'dispatcher'

urn 異常 避免 href 出現 view hist 異步 rop

今天在開發中遇到了一個問題,控制層使用的是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包的問題。

Could not resolve view with name '***' in servlet with name 'dispatcher'