zoukankan      html  css  js  c++  java
  • SpringMVC报错The request sent by the client was syntactically incorrect ()

    springmvc数据绑定出的错

    在数据绑定的时候一定要主意Controller方法中的参数名和jsp页面里的参数名字是否一致或者按照绑定的规范来写,

    如果不一致,可能回报如下错误: 

    The request sent by the client was syntactically incorrect ().

    从字面上理解是:客户端发送的请求语法错误。

    实际就是springmvc无法实现数据绑定。 
    查看一下你传的参数是不是有date类型等Springmvc不支持参数绑定的类型,需自己绑定

    date时间类型绑定 String-->date

    String--> date 时间格式

     1 package com.online.util;
     2 
     3 import java.text.ParseException;
     4 import java.text.SimpleDateFormat;
     5 import java.util.Date;
     6 import java.util.Locale;
     7 
     8 import org.springframework.format.Formatter;
     9 
    10 public class DateFormatter implements Formatter<Date>{
    11 
    12     
    13     public String print(Date object, Locale locale) {  
    14         return null;  
    15     }  
    16   
    17     public Date parse(String text, Locale locale) throws ParseException {  
    18         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
    19         Date date = null;  
    20         try {  
    21             date = format.parse(text);  
    22         } catch (Exception e) {  
    23             format = new SimpleDateFormat("yyyy-MM-dd");  
    24             date = format.parse(text);  
    25         }  
    26         return date;  
    27     }  
    28 }

    在Spring的applicationContext.xml中注入这个类

    1 <!-- 时间类型转换 -->
    2     <bean id="conversionService"  
    3         class="org.springframework.format.support.FormattingConversionServiceFactoryBean">  
    4         <property name="formatters">  
    5             <set>  
    6                 <bean class="com.online.util.DateFormatter"></bean>  
    7             </set>  
    8         </property>  
    9     </bean>  

    在Springmvc.xml中使用 mvc:annotation-driven注解配置

     1 <mvc:annotation-driven conversion-service="conversionService"/> 

     这样就是现了string-->date类型的转换
  • 相关阅读:
    google git的使用方法
    C/C++ 开发库 | C/C++ Development Library
    log4cplus c++开源日志系统
    c++配置类
    Markdown基础语法
    Nhibernate 映射关系,一对多 多对一与多对手在映射文件中的体现。
    Nhibernate refers to an unmapped class nhibernate问题的解决(初学者)
    UICollectionView的使用
    Runloop
    UITableView(转)
  • 原文地址:https://www.cnblogs.com/cmyxn/p/5895093.html
Copyright © 2011-2022 走看看