STRUTS2 type Converter Code time
Datetypeconverter.java
Package a.b;
Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import java.util.Date;
Import Java.util.Map;
Import Com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter;
public class Datetypeconverter extends Defaulttypeconverter {
@Override the public
Object Convertvalue (map< String, object> context, Object value, Class totype) {
SimpleDateFormat DateFormat = new SimpleDateFormat ("YYYYMMD D ");
try {
if (ToType = = Date.class) {//when the string is converted to the Date type
string[] params = (string[)) value;// Request.getparametervalues () return
dateformat.parse (params[0]);
else if (ToType = = String.class) {//when date is converted to a string,
date date = (date) value;
return Dateformat.format (date);
}
catch (ParseException e) {} return
null;
}
}
Xwork-conversion.properties (this file is placed in the Classes folder)
Java.util.date=a.b.datetypeconverter