eclipse-ee4j / glassfish

Eclipse GlassFish
https://eclipse-ee4j.github.io/glassfish/
377 stars 143 forks source link

problem with multipart/form-data #18202

Closed glassfishrobot closed 12 years ago

glassfishrobot commented 12 years ago

I have created a simple test servlet below to make this problem clear. Without the line request.getParameter("test"); commented out, uploadHandler.parseRequest(request) returns an empty list. This was not the case with Glassfish 3.0.1, or Tomcat 7.0.11.0.

I have also attached a very basic project to demonstrate the problem.

package com.rubiks.mavenproject26;

import java.io.IOException;
import java.io.PrintWriter;
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.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

/**
 *
 * @author derek
 */
@WebServlet(name = "NewServlet", urlPatterns = {"/NewServlet"})
public class NewServlet extends HttpServlet
{
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        response.setContentType("text/plain;charset=UTF-8");
        PrintWriter out = response.getWriter();

        try
        {
            request.getParameter("test");

            DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
            ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory);
            List<FileItem> items = uploadHandler.parseRequest(request);

            for (FileItem item : items)
            {
out.println(item);
            }
        }
        catch (FileUploadException e)
        {
            e.printStackTrace(System.err);
        }
        finally
        {
            out.close();
        }
    }
}

Affected Versions

[3.1.2_dev]

glassfishrobot commented 5 years ago
glassfishrobot commented 12 years ago

@glassfishrobot Commented kingsob said: I forgot to mention I am using Glassfish 3.1.2b17

glassfishrobot commented 12 years ago

@glassfishrobot Commented @barchetta said: In posting to dev@glassfish.java.net submitter stated problem was seen with 3.1.2b17

glassfishrobot commented 12 years ago

@glassfishrobot Commented kchung said: The glassfish implementation of multipart/form-data support in servlet 3.0 does not use apache-common-fileupload package. Hence, any references to the APIs in that package will probably not work. You should stick with servlet 3.0 apis.

glassfishrobot commented 12 years ago

@glassfishrobot Commented File: mavenproject26.tar.gz Attached By: kingsob

glassfishrobot commented 12 years ago

@glassfishrobot Commented Was assigned to kchung

glassfishrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA GLASSFISH-18202

glassfishrobot commented 12 years ago

@glassfishrobot Commented Reported by kingsob

glassfishrobot commented 12 years ago

@glassfishrobot Commented Marked as invalid on Tuesday, January 17th 2012, 9:49:28 am