Search code examples
javajsplast-modifiedfile-upload

setLastModified on jsp UploadFile


I need help how to set the last modified time on a file uploaded (on jsp).
I need to know the time when the file uploaded. This is my code but eclipse says "The method setLastModified(Date) is undefined for the type UploadFile".

Code:

 UploadFile file = (UploadFile) files.get("uploadfile");

 fName =file.getFileName();

 file.setLastModified(getthetime()); 

 upBean.store(mrequest, "uploadfile");

Solution

  • I think that the method you are trying to use is a method in the java.io.File API. Change

    file.setLastModified(getthetime()); 
    

    to

    new File(fName).setLastModified(getthetime()); 
    

    For what it is worth, I'm surprised that this would be necessary. I'd have thought that a file uploader would automatically set the modified time to the current time. (Or more accurately, that it would do nothing ... and let the OS set it by default.)

    What FileUpload class are you using?