JQuery uploadify plugin not working

Posted by Nitesh Panchal on Stack Overflow See other posts from Stack Overflow or by Nitesh Panchal
Published on 2010-04-29T10:18:35Z Indexed on 2010/04/29 12:47 UTC
Read the original article Hit count: 325

Filed under:
|
|

Hello,

I first used primefaces FileUpload component and it didn't work. Always gave "HTTP Error". So i thought there is some bug with this component and went to plain old JQuery and tried using uploadify. But still i get the same error. I am using Container Managed Security. Is this the reason for not working properly?

This is my script :-

 $(document).ready(function(){
                       $('#photoInput').uploadify({
                        'script'    : '/Blogger/fileUploadServlet',
                        'uploader'  : './uploadify/uploadify.swf',
                        'cancelImg' : './uploadify/cancel.png',
                        'auto'      : true
                        });

And this is my servlet which is never executed :-

package Servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

@WebServlet(name = "fileUploadServlet", urlPatterns = {"/fileUploadServlet"})
public class fileUploadServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, FileUploadException {
        PrintWriter out = response.getWriter();
        try {
            System.out.println("Executed!!");
            boolean isMultipart = ServletFileUpload.isMultipartContent(request);

            // Create a factory for disk-based file items
            FileItemFactory factory = new DiskFileItemFactory();

// Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload(factory);

// Parse the request
            List /* FileItem */ items = upload.parseRequest(request);

            Iterator e = items.iterator();
            while(e.hasNext()){
                System.out.println(e.next().toString());
            }

        } finally {
            out.close();
        }
    }
}

                      });

Please help me. I am stuck on this since 3 hours.

© Stack Overflow or respective owner

Related posts about servlets

Related posts about java