Uploadify plugin doesn’t call Java Servlet

This can have a lot of possible causes (also see the comments I posted).

  • External JS is not loaded.
  • JS code is syntactically/logically invalid.
  • Request URL is invalid.
  • Servlet is not mapped at all.
  • Servlet is mapped on wrong url-pattern.
  • Servlet failed to start/init.

It’s hard to naildown the root cause based on the as far given information.

As you mentioned that you didn’t see any request been fired in the “Net” tab of FireBug, I think that the JS code is simply syntactically/logically invalid. Rightclick page and doubleverify generated/printed JS code.

Update: I tried to reproduce your problem.

  1. I downloaded jquery.uploadify-v2.1.0 (MIT), extracted it and put the entire contents in the /WebContent/uploadify folder of my (empty) playground web project in Eclipse.

  2. I created a /WebContent/upload.jsp file as follows:

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <title>Uploadify test</title>
            <script src="https://stackoverflow.com/questions/2272160/uploadify/jquery-1.3.2.min.js"></script>
            <script src="uploadify/swfobject.js"></script>
            <script src="uploadify/jquery.uploadify.v2.1.0.min.js"></script>
            <script type="text/javascript">
                $(document).ready(function() {
                    $('#uploadify').uploadify({
                        'uploader': 'uploadify/uploadify.swf',
                        'script': 'uploadServlet',
                        'folder': '/uploads',
                        'cancelImg': 'uploadify/cancel.png'
                    });
                    $('#upload').click(function() {
                        $('#uploadify').uploadifyUpload();
                        return false;
                    });
                });
            </script>
        </head>
        <body>
            <input id="uploadify" type="file">
            <a id="upload" href="#">Upload</a>
        </body>
    </html>
    
  3. I created a com.example.UploadServlet as follows with little help of Apache Commons FileUpload (just placed commons-fileupload-1.2.1.jar and commons-io-1.4.jar in /WEB-INF/lib):

    package com.example;
    
    import java.io.IOException;
    import java.util.List;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.commons.fileupload.FileItem;
    import org.apache.commons.fileupload.disk.DiskFileItemFactory;
    import org.apache.commons.fileupload.servlet.ServletFileUpload;
    
    public class UploadServlet extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
        {
            System.out.println("UploadServlet invoked. Here are all uploaded files: ");
            try {
                List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
                for (FileItem item : items) {
                    if (!item.isFormField()) {
                        System.out.println("Name: " + item.getName());
                        System.out.println("Size: " + item.getSize());
                        System.out.println("Type: " + item.getContentType());
                    }
                }
            } catch (Exception e) {
                throw new ServletException(e);
            }
        }
    }
    
  4. I registered com.example.UploadServlet in web.xml as follows:

    <servlet>
        <servlet-name>uploadServlet</servlet-name>
        <servlet-class>com.example.UploadServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>uploadServlet</servlet-name>
        <url-pattern>/uploadServlet</url-pattern>        
    </servlet-mapping>
    
  5. I deployed the project, started the server, went to http://localhost:8080/playground/upload.jsp, selected a random big file from my downloads folder, clicked the Upload link, see the upload percentage counter growing to 100% and I finally see the following in the stdout:

    UploadServlet invoked. Here are all uploaded files: 
    Name: glassfish-v3-windows.exe
    Size: 50402555
    Type: application/octet-stream
    

I’m sorry to say, I can’t reproduce your problem. At least, the above information should help you to get started “freshly”. Hope it helps.

Update: as per the comments, the filter expects that it is using the same session. Ok, you can do this fairly easy by changing

'<%= request.getContextPath() %>/uploadFile?portletId=${portletId}&remoteFolder=<%= decodedString %>',";

to

'<%= request.getContextPath() %>/uploadFile;jsessionid=${pageContext.session.id}?portletId=${portletId}&remoteFolder=<%= decodedString %>',";

Leave a Comment