Check  File Existence and display  alert message

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.
//item.write(tosave);
          FileItemFactory factory = new DiskFileItemFactory();
          boolean isMultipart = FileUpload.isMultipartContent(request);
          System.out.println(isMultipart);
          Map fileDetails = new HashMap();
          ServletFileUpload upload = new ServletFileUpload(factory);
          List items = upload.parseRequest(request);
          Iterator iter = items.iterator();
          while (iter.hasNext()) {
               item = (FileItem) iter.next();
                    if (item.isFormField()) {
                                   String fieldName = item.getFieldName();     
                                   String fieldValue = item.getString();
                                   fileDetails.put("fileName",item.getString());
                    else {
                              fileDetails.put("path",item.getName());
                              cfile=new File(item.getName());
                              onlyFileName = cfile.getName();
               if (! folder.exists()) folder.mkdirs();
               if(cfile.exists()){  //THIS CHECK THE FILE EXISTENCE.  HOW CAN I DISPLAY ALERT MESSAGE TO USER HERE.
                    System.out.println("File Already Exists Path is ");     
Can anyone suggest me on this.

It won't work like that because JavaScript will run either before the form is submitted or after the page has been generated. In either case, you can't really communicate between the server side code and client side code.
What you can do is use Ajax to communicate with a servlet that checks for the duplicate file and responds accordingly. You can then perform the appropriate action on the page. This should be very simple to setup, take a look at this basic tutorial [1].
[1] http://www.w3schools.com/ajax/default.asp
People on the forum help others voluntarily, it's not their job.
Help them help you.
Learn how to ask questions first: http://www.catb.org/~esr/faqs/smart-questions.html
----------------------------------------------------------------

Similar Messages

  • How to stop a process from running and display a message

    I have a button that inserts data into a table based on bind variable selected on the page. I would like to add code to that button that will check to see if certain data already exists in the table, for that bind variable, and if that data already exists, stop the process and display a message that says "you have already inserted that information - bla bla bla". If not, continue inserting. What would be the best way to do this?
    Currently, the button is a plsql that inserts the data.
    Any help or examples would be greatly appreciated!
    mholman
    Edited by: user10488561 on Jul 27, 2009 8:48 AM

    Use a validation process for that. If the validation fails (data exists) the processes will not be run. If it doesn't then the processing will continue.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    ------------------------------------------------------------------------------

  • I have created a DVD via iMovie and burned several copies. When played the DVD's will stop and display a message SKIPPING DAMAGED Part. It is not the DVD. When trying to export the project, I get an error message.

    I have created a DVD via iMovie and burned several copies. It is a large file. When played the some DVD's will stop and display a message SKIPPING DAMAGED Part but will not resume. Some work fine.  It is not the DVD. I have burned from several batches. When trying to export the project, I get an error message with the following message: The project could not be prepared for publishing because an error occured (-108).

    TV video typically is copyrighted content.  We'd be breaking several rules trying to help you.  Good luck!

  • Hi! I have a WD my book external hard drive plugged into my imac and I want to share it over my network with my apple tv. I went into system preferences sharing, checked "file sharing" and added my external hard drive to the shared folder. So now it is

    Hi!
    I have a WD my book external hard drive plugged into my imac and I want to share it over my network with my apple tv. I went into system preferences > sharing, checked "file sharing" and added my external hard drive to the shared folder. So now it is listed in "shared folders" but under "users" everything is grayed out (it says "read and write" for "everyone" - but "read and write" is grayed out, and it doesn't let me add or subtract users). Now I can access all of the folders I shared from my imac except for the externalhard drive. What's going on?

    Hi RRFS!,thanks for help.I forgot to tell that hard drive has 2 partitions 1:format :Mac OS Extended (Journaled) and that works properly,2:format:MS-DOS (FAT32) and when i "get info" for both :first has shering & permitions:You can read and write - with name and privilege, second has shaing & prermissions:You can read and write- without name and privilege

  • My Ipad is locked and display a message that says " The Ipad hasnt been backed up in 2 weeks...........connected to wifi".  How do I come out of it?

    My Ipad is locked and display a message that says " The Ipad hasnt been backed up in 2 weeks...........connected to wifi".  How do I come out of it?

    Reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.

  • How to validate VO result and display error message?

    Hi,
    I have created 2 pages:
    Page 1: User to enter employee number and click 'Go' button to search (redirect to Page 2)
    Page 2: To display employee details
    In situation where employee is suspended, employee detail will be display as blank in Page 2.
    At the same time, we would like to display error message which inform user to refer to HR Department for this scenario.
    Need guidance on how to perform the validation and display error message.
    Thanks and Regards,
    Shiau Chin

    Hi Shiau,
    In this case instead of redirecting to next page, throw an exception on the same page.
    If you want redirect it to next page then while redirecting it to next page pass some info that can indicate that employee is suspended, get this value in Process request if it has value then throw exception else query details.
    Regards,
    Reetesh Sharma

  • I have been using CS6 for two years without incident.  Suddenly the Media Encoder stops working, showing APPCRASH and displaying error message about WatchFolder.dll - I tried uninstalling and re-installing to no avail - can anyone help

    I have been using CS6 for two years without incident.  Suddenly the Media Encoder stops working, showing APPCRASH and displaying error message about WatchFolder.dll - I tried uninstalling and re-installing to no avail - can anyone help?

    Hi Mylenium,
    Thanks for your response.
    Here is the error information showing up:
    Problem signature:
      Problem Event Name: APPCRASH
      Application Name: Adobe Media Encoder.exe
      Application Version: 6.0.0.382
      Application Timestamp: 4f62fcf1
      Fault Module Name: WatchFolder.dll
      Fault Module Version: 6.0.0.382
      Fault Module Timestamp: 4f62f37f
      Exception Code: c0000005
      Exception Offset: 0000000000007899
      OS Version: 6.1.7601.2.1.0.768.3
      Locale ID: 4105
      Additional Information 1: 9a62
      Additional Information 2: 9a620826d8ae4a2fa8b984b39290a503
      Additional Information 3: 1fb3
      Additional Information 4: 1fb304eee594288faeefbf1271b70d37
    I am using a PC Windows 7

  • Face time will not connect error message "Please check network conections and Try again" message appears but I'm connected to the internet?

    Face time will not connect error message "Please check network conections and Try again" message appears but I'm connected to the internet?

    Hey sergioo9,
    Thanks for the question. Based on what you stated, it seems like you are having trouble signing into Messages on OSX. I would recommend that you read this article, it may be able to help you resolve or isolate the issue.
    FaceTime, Game Center, Messages: Troubleshooting sign in issues - Apple Support
    Thanks for using Apple Support Communities.
    Cheers,
    Mario

  • Can't reinstall osx lion from internet, and display a message"cannot find installation information ,please contact applecare, what should i do?

    hello
    I can't reinstall osx lion from internet, and display a message"cannot find installation information ,please contact applecare, what should i do?
    thanks

    I'm no Lion expert, but I believe you can boot from the Recovery partition by pressing the Command and R keys on startup, then reinstall.

  • Getting file location and display!

    Hello friends,
    I need to find out the file path and display it using java.
    Is it any specific java cmd for it.
    For example, if i store a file in d:/javaworks/ram/one.txt, then i need to retrieve the path and show it in command window.
    pls, reply me as soon as possible.

    For example, if i store a file in d:/javaworks/ram/one.txt, then i need to retrieve the path and show it in command window.Using your example above, since you know where you placed it, use
    System.out.println("d:/javaworks/ram/one.txt");

  • Customize Alert messages for checking duplicate value and Success alert

    Hi All,
    I want to show two alert against the same "Submit" button to--
    1. Alert messages for checking duplicate value and show the Duplicate value found alert and
    2. Success Alert if the form is success to commit and no duplicate value found.
    I did all thing but when alert-1 shows and i pressed the ok button of the alert then the second alert also shows which i don't want to show.
    Which i can do in this issue? Have there anyone to help me!
    Arif

    Hi Manu,
    I have placed the following code
    1. against the Submit button--
    if error_code=40508 then
         commit_form;
    elsif :USERDELETION.CANCELLATION_USERID is not null then
    do_key('COMMIT_FORM');
    else null;
    end if;
    2. Code against the key-commit trigger in the form level--
    commit_form;
    DECLARE
    vAlert NUMBER;
    BEGIN
    set_alert_property('ALERT_TO_VERIFY',ALERT_MESSAGE_TEXT, 'Your Form has successfully submitted and your Reference id is '||:USERDELETION.REF_NO);
    vAlert:=SHOW_ALERT('ALERT_TO_VERIFY');
    END;
    3. Code against the on-error trigger in the form level--
    DECLARE
    vAlert NUMBER;
    BEGIN
         if ERROR_CODE = 40508 then
    set_alert_property('ERROR_ALERT',ALERT_MESSAGE_TEXT, 'This user deletion request has already submitted of the user named '||'"'||:USERDELETION.FULLNAME||'"');
    vAlert:=SHOW_ALERT('ERROR_ALERT');
    elsif
              ERROR_CODE = 40202 then
    set_alert_property('ERROR_ALERT',ALERT_MESSAGE_TEXT, 'Existing userid must be filled-up !');
    vAlert:=SHOW_ALERT('ERROR_ALERT');
    else
                   message(error_type||to_char(error_text)||': '||error_text);
    end if;
    END;
    If there have any confusion, please ask me.
    Arif

  • How to display alert message box in sharepoint 2013 visual web part?

    Hi,
    I am developing a visual web part which submits data to the list. Once it submits the data, I should convey to the user that the data has been submitted successfully.
    I tried using clientScript.RegisterStartUpScript etc, but, none of them are working. It is not throwing any error , but pop up is not getting displayed.
    Preferrably, I would like to call this alert message from cs page, because, I will be using it in several places.
    Please help me.!
    Thanks in advance.
    Hepsi

    Hepsi, 
    Step 1. On the Page_Load - This way you can pass parameters. Try this
    btn.Attributes.Add(
    "onclick", string.Format("return openSPPopup('{0}?{1}={2}', '{3}')", YourPage_URL, var1_Name, value1, Param1_PopupTitle));
    Step 2 : Javascript function
    function openSPPopup(navigateURL, popUptitle) {
    var options = {
    width: popupWidth,
    height: popupHeight,
    url: navigateURL,
    scroll: 0
    SP.UI.ModalDialog.showModalDialog(options);
    return false;
    Step 3: The popup close code (in .cs file) – I do it this way as it is just close dialog code and easy to write.
    protected void btnClose_Click(object sender, EventArgs e)
    { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "SP.UI.ModalDialog.commonModalDialogClose(1, 1);", true);
    Courtesy -
    Thread
    Try this - https://bramdejager.wordpress.com/2011/03/21/using-sp-ui-dialog-and-sp-ui-notify-from-code-behind/
    http://msdn.microsoft.com/en-us/library/ff798390.aspx
    http://stackoverflow.com/questions/9833907/asp-net-confirm-before-executing-codebehind
    http://www.codeproject.com/Questions/443131/Call-to-javascript-Function-from-code-behind-using
    http://www.c-sharpcorner.com/uploadfile/ledomoon/calling-code-behind-function-in-javascript/
    Hope they will help!
    Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

  • Displaying alert message based on user input on input param screen

    Hi,
    Based on user input I wish to display an alert popup on my report. I
    have provided the user 2 dropdowns called sortasc and sortdesc with all
    the column names used in the report to simulate dynamic sorting.This is
    because we do not have dynamic sorting in CR XI R2. When the user
    selects same column name in both sortasc and sortdesc then the sort
    type which has priority in the record sort expert is executed. This is fine but we want an alert
    or message popup displayed so as to prevent user from selecting same
    column names.
    I tried adding an alert with the following code:
    if {?sortasc} = {?sortdesc} then true else false
    So far I have not been prompted with any alert message box.
    Let me know if there is any other option.

    Hi Shalu,
    I have created a alert and it is working fine, please follow the steps
    Create a new Alert using two static parameters and give the condition for message like :
    if {?Myworld} = {?Myworld1} Then
    'You have entered a correct word'
    else
    'This is not a correct word'
    Then create a condition like :
    {?Myworld} = {?Myworld1} or {?Myworld} <> {?Myworld1}
    Also check the check box Enabled and save the alert.  Now it will popup if the myworld is equal to myworld1 or myworld is not equal to myworld1.
    Hope this will help you
    Thanks,
    Sastry

  • File name and displaying images

    I am trying to rename all the jpg files i have in my directory, to consecutive number. eg. 1.jpg, 2.jpg. as a new comer to the java world, im not too sure if i have doen it right. could you check...
    Also, after i renamed the files i want the images displayed side by side across the screen..
    This is teh code...
    import java.awt.*;
    import java.applet.Applet;
    import javax.swing.*;
    import java.io.*;
    import java.io.File;
    import java.io.IOException;
    public class GetImages extends Applet {
         public static void main(String[] args) throws IOException
    // File (or directory) with old name
        File file = new File("picture1.jpg");
        // File (or directory) with new name
        File file2 = new File("1.jpg");
        // Rename file (or directory)
              int xx;
              xx = 0;
       if (xx<500) {
       file.renameTo(new File(xx+".jpg"));
         xx++;
    private Image image;
    public void init() {
       image = getImage(getDocumentBase(), (xx+".jpg"));
    public void paint(Graphics g) {
         int x, y, counter, numberOfImages;
    x = 0;
    y = 0;
    counter = 1;
    numberOfImages = 21;
    while (counter != numberOfImages) {
              g.drawImage(image, x, y, 15, 15,this);
              x = x + 15;
              counter++; im not too sure where i am goign wrong?

    You're really trying to do two things: rename the files and display the images. Let's work on one at a time. First, to rename the files, you'll need to get a list of the files in the directory. Look at the Javadocs for java.io.File (http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html) for the way to do this.
    Once you have the list of files, you need to loop through them and rename each one. A for loop will be a good way to do this. You'll have an array of Files, so your code might look something like this:
    // Get your array of Files and call it something simple like 'files'
    int numFiles = files.length;
    for( int x = 0; x < numFiles; x++ )
    // Rename the file
    }The for loop will start at 0 and loop until x is equal to numFiles.

  • How to compare two currency form fields and display a message if the fields do not equal?

    My form has 2 fields named Total_1 and Total_2. If one of the fields does not equal the other, a hidden field will display a message in red on the form alerting the user. Otherwise, the message does not display. Looks like a validation script but I would greatly appreciate help in getting it started. Any ideas?
    Thanks, Charlie
    charlie6067

    Since the field values that you want to compare are the results of calculations, you should not normally compare their string values, but rather their numeric values when rounded appropriately (and perhaps then converted to a string). For example, if you have two values that display as 3.14, one could be 3.1400000001 and the other could be 3.13999999999991234. When you get the field values as strings and compare them, they won't be equal though they appear to be. Even some values that are numerically identical won't be equal when compared as strings ("0.0" != "0.00") So the code could be changed to:
    // Get the two field values, rounded to two decimals
    var v1 = util.printf("%.2f", getField("Total_1").value);
    var v2 = util.printf("%.2f", getField("Total_2").value);
    // Hide/Show the error message
    event.value = (v1 === v2 || (+v1 === 0 && +v2 === 0)) ? "" : "Error message here.";

Maybe you are looking for

  • Creating rules for other mailboxes

    Hi there, I couldn't seem to find this question anywhere so I'll just post it. Is there a way to create a rule for IMAP mailboxes? Here is my situation: I have two gmail IMAP accounts in Mail in addition to my .Mac IMAP account. Now sometimes I can't

  • Cant add Apps to login items with profile manager

    I can set up profile manager successfully, and set certain settings like the Dock, the login window, etc. But when I click on Login Items, and try to add an Application, the list of applications is blank. Tried it from my server, tried it logged in r

  • Problem viewing Argo - subtitles

    Rented the movie ARGO and experienced issue of subtitles remaining on screen.  Only way to get subtitles off was to stop movie, exit out of movie and then resume playing.  Extremely annoying as I had to repeat process about 20 times.  Same issue occu

  • 2LIS_03_BX    Marker

    I have received many help to understand inventory management. One very helpfull indication was "How to handle inventory management scenarios in BW". I have one question about the marker. As I understood, after executing all the steps of 2LIS_03_BX th

  • Version management for SAP Screens?

    Hi, I need to do version comparison  for sap screens . My source system is R/3 4.7 & Target system is ECC 6.0.