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類型的轉換

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM