struts时间格式转换问题处理方案:
采用插件处理机制。代码如下:
package heroking.etc;
import org.apache.struts.action.PlugIn;
import javax.servlet.ServletException;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.SqlDateConverter;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.config.ModuleConfig;
public class ConverterPlugIn implements PlugIn {
public void init(ActionServlet servlet,ModuleConfig config) throws ServletException{
ConvertUtils.register(new SqlDateConverter(null),java.sql.Date.class);
ConvertUtils.register(new SqlDateConverter(null),java.sql.Timestamp.class);
}
public void destroy(){
ConvertUtils.deregister();
}
}
struts-config.xml配置如下:
<plug-in className="heroking.etc.ConverterPlugIn"/>