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

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

  1. 頁面跳轉:
    出現這種異常可能是由於返回值不對,本例中返回值實際上應該是:jtyd/HistoryDetail。僅僅是一個字母的差別。
  2. json返回:
    出現這種異常可能是因爲在配置文件中配置了:
 <property name="defaultContentType" value="text/html" />

想要糾正就需要改爲:<property name="defaultContentType" value="application/json" />
或者在每一個適配器(請求的方法)上面加上@ResponseBody註解。

個人認爲第二種情況出現的錯誤比較少見,常見的還是第一種情況,即寫錯了返回值。所以在書寫代碼的時候一定要注意避免出現書寫錯誤,細心就行。

備註:
關於第二種配置的問題,個人開發過程中還沒有嘗試在配置文件中添加返回頭的配置,都是通過書寫@ResponseBody註解來解決異步請求的返回值處理問題的。

遇到一個比較詳細的案例:http://blog.csdn.net/abc360200314/article/details/22862727
出的問題是一樣的,但是解決方式不同,目前還沒有去看jar包的問題。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章