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类型的转换
  • 相关阅读:
    wireshake抓包,飞秋发送信息,python
    python问题:IndentationError:expected an indented block错误解决《转》
    560. Subarray Sum Equals K
    311. Sparse Matrix Multiplication
    170. Two Sum III
    686. Repeated String Match
    463. Island Perimeter
    146. LRU Cache
    694. Number of Distinct Islands
    200. Number of Islands
  • 原文地址:https://www.cnblogs.com/cmyxn/p/5895093.html
Copyright © 2011-2022 走看看