开发者

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");


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?


Seems like the message by Eclipse is self-explanatory. In the class UploadFile, there is no method called 'setLastModified'. Therefore, the compilation fails.

What is the fully-qualified classname of UploadFile class? Is it something that you wrote or is it from a third-party library?

Once you get a reference to the java.io.File object, use the setLastModified method in that class to set the time.

You might find it interesting to take a look at Apache Commons File Upload library. It is a well known third-party library that is used to handle file upload operations in Java (see http://commons.apache.org/fileupload/).

This link http://www.servletworld.com/servlet-tutorials/servlet-file-upload-example.html is an example of using Commons File Upload.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜