tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Priest <>
Subject RE: Form and ENCTYPE=multipart/form-data
Date Thu, 15 May 2003 19:32:03 GMT
Are your parameters contained inside the form? If so, You have to call the
fileupload.parseRequest() method first and then retrieve you're parameters
from the list of file items that that call returns.

A multipart form request is structured differently than your usual post form
request, so you can't just call request.getParameter().

take a look at my upload jsp file:

--------------------------------- file

<%@ page
    info="Test File Upload Page"


<body bgcolor="white">

static int MAX_UPLOAD_SIZE=-1; //no limit
static String TEMP_DIR = "C:\\temp\\uploaded_files";
static Category cat = Category.getInstance("FileUpload");


   //set up the directory uploaddir=new;

    // Create a new file upload handler
    DiskFileUpload upload = new DiskFileUpload();

    // Set upload parameters

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

    out.print("upload called!");

<Table border="3">


    // Process the uploaded fields
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem);

        if (item.isFormField()) {
            out.println("<tr><td><b>Form Field<b></td><td>
Field Name:
            +"<td>"+  item.getString() + "</td></tr>");
        } else {
        String newFileName =
        //write the file
        item.write(TEMP_DIR+"\\" + newFileName);
        out.println("<tr><td><b>File<b></td><td> File
          +"<td>"+  newFileName + "</td></tr>");




-----Original Message-----
From: []
Sent: Thursday, May 15, 2003 3:12 PM
To: Tomcat Users List;
Subject: Re: Form and ENCTYPE=multipart/form-data

I'm actually aware of those classes and the Jakarta commons equivalents.  My
question is not about processing the data once the servlet gets it - rather
it's about getting it to the servlet!  You see, whenever I add the ENCTYPE
tag, the form seems to magically stop sending any of it parameters to the
servlet?  I'm sure I'm missing some small thing - but I cannot find it yet.
Any thoughts?

---------Original Meassage---------

Check out the MultipartFilter and MultipartRequest classes and other
documentation at This seems to be
the defacto method of uploading files using Servlets. Works for me. Only
caveat is that there's a hard-coded 1MB file limit... I had to go into the
source code and increase it for my purposes, but wasn't hard.

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message