2017-05-28 6 views
0

をsubmiitingながら、私は次のコードを使用して、日付の書式を設定しています:として春日付変換エラーフォーム

@InitBinder 
public void initBinder(final WebDataBinder binder) { 
    binder.initDirectFieldAccess(); 

    final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); 
    dateFormat.setLenient(false); 
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); 
} 

とJSPから同じ形式で日付を送るが、エラーを取得する:

失敗

型[Java.Lang.String]のプロパティ値を必須型に変換するには[Java.Util.Date]プロパティBidDate;ネストされた例外は、java.lang.IllegalArgumentExceptionがです:日付を解析できませんでした:解析できない日:「2017年5月28日は」

答えて

1

あなたの日付形式はdd/MM/yyyyですが、あなたはそれをMM/dd/yyyy日(05/28/2017

1

からを渡しますJSPは、クラスで指定されているものとは異なる日付形式になります。つまり、JSP05/28/2017 (MM/dd/yyyy)を送信し、クラスが28/05/2017 (dd/MM/yyyy)の形式を待っていることを意味します。

だから、あなたはこれを変更しようとすることができる。このため

final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); 

を:

final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); 

または、順番に、あなたのJSP

をして日付形式を変更することができます