SpringMVC报错The request sent by the client was syntactically incorrect ()

 2023-09-05 阅读 127 评论 0

摘要:springmvc数据绑定出的错 在数据绑定的时候一定要主意Controller方法中的参数名和jsp页面里的参数名字是否一致或者按照绑定的规范来写, 如果不一致,可能回报如下错误: 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类型的转换

 

转载于:https://www.cnblogs.com/cmyxn/p/5895093.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/980.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息