File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Conversion of string to date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Conversion of string to date" Watch "Conversion of string to date" New topic
Author

Conversion of string to date

Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
Hi,
i'm trying to develop a module which reads the date from the Web page as inputed by the user and stores the date in the database.

My JSP page is as follows:


and the java file is as follows:



now when i'm trying to compile in the using ANT its giving the follwowing error:



please help
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

parse method has two overloaded forms

parse(String) and parse(String source, ParsePosition pos)

but your code seems to be passing a Date object.


Swastik
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
the JSP page is sending the input as String only.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

May be. But look at your method call

Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
I made the changes and removed the parser from the statement where the method returns the value but it is still giving the same error for the one parser in the setDate method
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
i made the changes, now the code is:



and the error during compiling is:
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

Look at the error
java.text.ParseException; must be caught or declared to be thrown

so you should either throw the exception or catch it
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
Thanks... now the code gets compiled and is running..
but not according hoe it should..
the code is now..


its sending the date as "null"

I checked the logs and its something like this:
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

What is the use of following line?
private Date dates=null;
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
Its used for intializing and local declaration of the variable "dates"
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

try one thing, put two print statements in this method to make sure you are getting the values properly.



and in

Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
I did the additions suggested by you. Now the log is:



The print statements in the setDate() weren't even executed.. so I think there might be a problem with that.
I even tried changing

public void setDate(String value)

to

void setDate(String value)

but that also gave the same result
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

try this once
in your execute method


make that dates variable as String


and change the definition of setDate and getDate as follows
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
Made the changes suggest by you. The code is now



and while compiling its giving an error:
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6



should be
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
its giving an error "incompatible types"


so i made a change and converted


to


it compiled properly but while running struts gave an error:
Mai Vala
Greenhorn

Joined: Mar 31, 2010
Posts: 14
format method takes date datatype as method parameter and returns String...
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
I changed the code from



to


and it compiled and was able to execute.. but the "null" problem is still there.
the logs are:
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

There is small mistake in the code that Mai has pointed out, you need to call parse not format. However this does not seem to be related to the null issue.
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
I changed format to parse.... Only after making the change the file is able to be executed....
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

The problem is setter method for date is not getting called.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Conversion of string to date
 
Similar Threads
Problems with bean example
Difficulty in executing
javax.servlet does not exist
unable to compile servletListener
Compiling java file