zoukankan      html  css  js  c++  java
  • 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包的问题。

  • 相关阅读:
    Jersey的异常处理
    REST响应处理
    jersey REST的接口简述
    Firebird 同一字段的多行合并为一行
    Firebird/InterBase内置函数使用说明
    发布FireBird数据库所需要DLL文件
    unidac连接FireBird数据库
    打开与关闭Linux防火墙
    Linux FTP 命令
    Linux 命令修改系统时间
  • 原文地址:https://www.cnblogs.com/lilinzhiyu/p/7921854.html
Copyright © 2011-2022 走看看