zoukankan      html  css  js  c++  java
  • SSM搭项目报错:HTTP Status 400 – Bad Request

    具体报错如下:

    Type Status Report

    Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

    在用表单提交数据的时候,出现如上所示的错误。根据描述可以看出事客户端数据提交时发生的错误,可能是请求的语法或者路径错误。

    最后发现,表单提交的时候,日期类型是按照字符串提交的,而服务器用的Date类型来接,所以会出错,在控制器里添加代码:

        @InitBinder
        public void init(WebDataBinder webDataBinder){
            //指定什么格式,前台传什么格式
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            simpleDateFormat.setLenient(false);
            webDataBinder.registerCustomEditor(Date.class,new CustomDateEditor(simpleDateFormat,false));
        }
        @InitBinder
        public void init(WebDataBinder webDataBinder){
            //指定什么格式,前台传什么格式
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            simpleDateFormat.setLenient(false);
            webDataBinder.registerCustomEditor(Date.class,new CustomDateEditor(simpleDateFormat,false));
        }

    由此便可解决问题。

    如果提交的表单时,如果某些数据没有填,而后台做出了“接收”的行为,也会报如上错误。

  • 相关阅读:
    IDEA使用总结1-Github下载代码和上传代码到Git
    Mysql-安装指南
    Dubbo安装及其实战1
    分布式设计(学习内容目录--后端架构师)
    elasticsearch安装指导(new)
    浅谈TCP/IP(new 常见面试问题)
    浅谈常用的设计模式(new)
    浅谈Elasicsearch
    浅谈数据库分库分表(new)
    JAVA 电子书下载地址
  • 原文地址:https://www.cnblogs.com/phdeblog/p/10529773.html
Copyright © 2011-2022 走看看