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 时间格式

 package com.online.util;

 import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale; import org.springframework.format.Formatter; public class DateFormatter implements Formatter<Date>{ public String print(Date object, Locale locale) {
return null;
} public Date parse(String text, Locale locale) throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = format.parse(text);
} catch (Exception e) {
format = new SimpleDateFormat("yyyy-MM-dd");
date = format.parse(text);
}
return date;
}
}

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

 <!-- 时间类型转换 -->
<bean id="conversionService"
class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="formatters">
<set>
<bean class="com.online.util.DateFormatter"></bean>
</set>
</property>
</bean>

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

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

 这样就是现了string-->date类型的转换
上一篇:错误:The request sent by the client was syntactically incorrect的解决


下一篇:错误400-The request sent by the client was syntactically incorrect