3 Replies Latest reply on Mar 15, 2007 3:29 PM by 569573

    validating existance of file on the server

      My application requires certain files to be uploaded by the user to the server. I am intending to validate the process, that is: if the user has not uploaded the files or the files are not on the server then a prompt message should be displayed asking the user to upload required files.
      Can we embed JSP in Java script ? I was thinking using "onsubmit" tag in my html form and pointing it to a validation function in java script. In java script I may use JSP tag for finding out the existance of a certain file.
      For instance, checkFile can be a method written in JSP tags as:
      public String checkFile()
          File ch3 = new File("path/file name") ;
          if (ch3.exists() == true)
              return f3 ; // file found
              return f3not ; // file not found
      and then within java script i may call the method checkFile() as:
      function validate_file ( )
               valid = true;
                f3 = "ftn03" ;
                if ( "<%= checkFile() %>" != f3)
                         alert("Please upload the required files") ; 
                          valid = false;
                      return valid;
      I don't think I can use JSP tags within Java script. Can anyone suggest something, or point me in some direction ?

      Message was edited by:
        • 1. Re: validating existance of file on the server
          You can use JSP to generate HTML, why not for Javascript ?

          But suppose you have 2 users access this JSP and first user uploaded a file and second user won't know until refresh the JSP again.

          A better approach is validating on Servlet (or JSP if you like), and tell the user if upload is successful.
          • 2. Re: validating existance of file on the server
            can you explain it a bit more ?
            I have this html form button "proceed". If a user click proceed, then how can I relate the click event to the validation. I mean, previously, I had been using java script function. I was calling that function from proceed button as "onSubmit = java script method". How can I refer onSubmit to a JSP page ? Can I use the JSP page name in the onSubmit option ?
            Thanks again.
            • 3. Re: validating existance of file on the server
              If you really want a checking on javascript but accessing the data dynamically.
              I would success you use something like AJAX.
              But if make it simple, assume you have two frames (HTML), content and temp.
              When the "submit" button is pressed in content, send the form in "temp".
              "temp" will be updated and javascript will be called to display useful information.

              But the simplest way is to submit the form and do validation on server.