views:

439

answers:

1

Hello All,

I am new to Jquery, I have a problem regarding uploading the files using Uploadify. Iam trying to send a file to the Java Servlet which uploads the file using apache commons. But while executing the code, it is not all going to servlet. I actually took this sample example from web and trying it. Can anyone advice what am i missing? I am pasting the client code below:

My understand is "script" parameter in uploadify function will call the servlet. so, I have written my Servlet name in script parameter.

Please advice me how to proceed further.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

SimpleFileUpload

    <script type="text/javascript">
        $(function() {
            $('#file_upload').uploadify({
                'uploader' : 'swf/uploadify.swf',
                'script' : 'fileupload',
                'cancelImg' : 'img/cancel.png',
                'multi' : false
            });
        });
    </script>
</head>
<body>
    <h1>Simple File Upload</h1>

    <h3>Multiple file upload made easy</h3>

    <div id="file_upload"></div>
    <br/>
    <input type="button" value="Clear Queue" onclick="$('#file_upload').uploadifyClearQueue();"/>
    <input type="button" value="Submit Queue" onclick="$('#file_upload').uploadifyUpload();"/>
</body>

and my servlet code is

protected void doPost(HttpServletRequest request, HttpServletResponse response)               throws ServletException, IOException {

 if (ServletFileUpload.isMultipartContent(request)){
    // Parse the HTTP request...
  try {
  ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
  List fileItemsList = servletFileUpload.parseRequest(request);

  Iterator itr = fileItemsList.iterator();

  while(itr.hasNext()) {
   FileItem item = (FileItem) itr.next();

  // check if the current item is a form field or an uploaded file
   if(item.isFormField()) {

  // get the name of the field
   String fieldName = item.getFieldName();

 // if it is name, we can set it in request to thank the user
  if(fieldName.equals("name"))
  request.setAttribute("msg", "Thank You: " + item.getString());

   } else {


    File fullFile  = new File(item.getName()); 


    String filename = item.getName();



     File targetdir = new File("E:/");
   File savedFile = new File(targetdir,fullFile.getName());
     item.write(savedFile);

   }
  }
  }
     catch(Exception e)
     {
      e.printStackTrace();
     }
  } //end servletFileUpload

Thanks,

A: 

I just used swfupload... Using fiddler i was seeing my basic example only was submitting 1 file with uploadify so i gave up on it.

armyofda12mnkeys