• 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返回。

    页面跳转: 

    出现这种异常可能是由于返回值不对,本例中返回值实际上应该是: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包的问题。

  • 相关阅读:
    swfupload多文件上传[附源码]
    C#函数式程序设计之泛型(下)
    ASP.NET MVC实现POST方式的Redirect
    使用Windows Azure的VM安装和配置CDH搭建Hadoop集群
    Asp.Net MVC 上传图片到数据库
    ASP.NET Web API标准的“管道式”设计
    如何捕获和分析 JavaScript Error
    快学Scala习题解答—第一章 基础
    职场人生
    合伙人的重要性超过了商业模式和行业选择(转)
  • 原文地址:https://www.cnblogs.com/lilinzhiyu/p/7921854.html
Copyright © 2020-2023  润新知