简体   繁体   English

StandardWrapperValve [jsp]:Servlet jsp的Servlet.service()抛出异常java.lang.IllegalArgumentException:无法将给定对象格式化为日期

[英]StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception java.lang.IllegalArgumentException: Cannot format given Object as a Date

I am getting exception in my java jsp servlet code I am getting the error mentioned in the title. 我的java jsp servlet代码中出现异常,标题中提到了错误。
I tried the solution from the link already from stackoverflow which is mentioned below but no use.. 我已经从下面提到的stackoverflow链接中尝试了解决方案,但是没有用。

My problem is null value is entered into the mysql database..I am stuck in it for two days already.. 我的问题是将空值输入到mysql数据库中。我已经在其中停留了两天。

Java : Cannot format given Object as a Date Java:无法将给定对象格式化为日期

 import java.sql.Timestamp;    
 import java.text.ParseException;    
 import java.text.SimpleDateFormat;   
 import java.time.Instant;   
 import java.util.Date;   
 import java.util.logging.Level;   
 import java.util.logging.Logger;

 public class SetDate  
 {  
 public static java.util.Date set(String s,String f)    
 {   
 java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat(f);    
 java.util.Date date=null;   
 try  
 {    
 date=sdf.parse(s);    
 }     
 catch (ParseException ex)  
 {    
 Logger.getLogger(SetDate.class.getName()).log(Level.SEVERE, null, ex);   
 }      
 return date;     
 }    


public static String format(Object time,String f) throws ParseException   
{      
    SimpleDateFormat sdf=new SimpleDateFormat(f);       
    System.out.println("Date:- " +sdf.format(time));        
    return sdf.format(time);        
}   
}

Error logs: 错误日志:

Warning:   StandardWrapperValve[jsp]: Servlet.service() for servlet jsp   threw exception
java.lang.IllegalArgumentException: Cannot format given Object as a Date      
at java.text.DateFormat.format(DateFormat.java:310)       
at java.text.Format.format(Format.java:157)       
at myweb.tool.SetDate.format(SetDate.java:35)        

Change: 更改:

public static String format(Object time,String f) throws ParseException   
{      
    SimpleDateFormat sdf=new SimpleDateFormat(f);       
    System.out.println("Date:- " +sdf.format(time));        
    return sdf.format(time);        
}   

to: 至:

public static String format(Object time,String f) throws ParseException   
{   
    if (time == null) 
        rteurn null;

    SimpleDateFormat sdf=new SimpleDateFormat(f);       
    System.out.println("Date:- " +sdf.format(time));        
    return sdf.format(time);        
}   

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:StandardWrapperValve [jsp]:servlet jsp的Servlet.service()抛出异常java.lang.NullPointerException glassfish - WARNING: StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception java.lang.NullPointerException glassfish 警告:StandardWrapperValve [jsp]:PWC1406:servlet jsp的Servlet.service()抛出异常java.lang.NullPointerException - WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception java.lang.NullPointerException JSP NullPointer StandardWrapperValve[servlets. ]:用于 servlet servlet 的 Servlet.service()。 抛出异常 java.lang.NullPointerException - JSP NullPointer StandardWrapperValve[servlets. ]: Servlet.service() for servlet servlets. threw exception java.lang.NullPointerException servlet [jsp] 的 Servlet.service() 抛出异常 - Servlet.service() for servlet [jsp] threw exception 为什么servlet jsp的Servlet.service()抛出异常java.lang.NullPointerException? - Why Servlet.service() for servlet jsp threw exception java.lang.NullPointerException? 严重:Servlet [jsp]的Servlet.service()抛出异常java.lang.NumberFormatException - SEVERE: Servlet.service() for servlet [jsp] threw exception java.lang.NumberFormatException Servlet jsp的Servlet.service()引发了异常java.lang.IllegalStateException - Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException Spring 微服务:servlet [jsp] 的 Servlet.service() 抛出异常 - Spring microservice: Servlet.service() for servlet [jsp] threw exception StandardWrapperValve [web.dbServlet]:servlet web.dbServlet的Servlet.service()抛出异常java.lang.NullPointerException - StandardWrapperValve[web.dbServlet]: Servlet.service() for servlet web.dbServlet threw exception java.lang.NullPointerException StandardWrapperValve [Jersey Web Application]:Servlet Jersey Web Application的Servlet.service()抛出异常java.lang.NullPointerException - StandardWrapperValve[Jersey Web Application]: Servlet.service() for servlet Jersey Web Application threw exception java.lang.NullPointerException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM