aspose file tools*
The moose likes Servlets and the fly likes check File Existence and display alert message    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "check File Existence and display alert message    " Watch "check File Existence and display alert message    " New topic
Author

check File Existence and display alert message

Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
Hi,

I have a servlet which uploads file to server. Below is my code and is working file. Now, I want to check if the file uploading by the user is already exists. If so , I have to display a message to user "The file you are trying to upload already exists. Do you want to overwrite" with YES or NO actions.

How can I display this alert message from user.



Can anyone suggest me on this?
[ October 30, 2007: Message edited by: Ben Souther ]
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

You can render a new page and display the message, or you can use ajax to upload file, and if file exists on the server display an alert using ajax.


[Servlet tutorial] [Servlet 3.0 Cook Book]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42590
    
  65
Rendering a new page informing the user is the way to go.

AJAX has no concept of files, and so can't be used for the upload.


Ping & DNS - my free Android networking tools app
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212


AJAX has no concept of files, and so can't be used for the upload.[/QB]


Why not?
You can use ajax to upload files. do some googling you will find read made code.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42590
    
  65
Originally posted by sudhir nim:
Why not?
You can use ajax to upload files. do some googling you will find read made code.

AJAX can send data to the server, but it can't upload files because JavaScript has no access to the client file system.
Senthil Kumar
Ranch Hand

Joined: Oct 14, 2007
Posts: 33
Rohit,
You can try setting a request atribute in the servlet once you find the file already exists in the location.
1.In the JSP write a scriplet for getting the attribute value and assign it to variable declared in the scriptlet.
2.Now declare a variable in the Javascript and assign scriplet variable's value to this script variable.
3.You have to write an ONLOAD event Handler.
In that function,check the javascript variable and display the alert.
I think this will work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: check File Existence and display alert message