tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Priest <Robert.Pri...@bentley.com>
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
upload.jsp--------------------------------------------------

<%@ page
    info="Test File Upload Page"
    language="java"
    import="org.apache.commons.fileupload.*,
            org.apache.log4j.Category,
            org.apache.log4j.Priority,
            java.util.*"
%>


<html>

<body bgcolor="white">

<h1>
<%!
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
    java.io.File uploaddir=new java.io.File(TEMP_DIR);
    uploaddir.mkdirs();


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

    // Set upload parameters
    upload.setSizeMax(MAX_UPLOAD_SIZE);
    upload.setRepositoryPath(TEMP_DIR);

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

    out.print("upload called!");

%>
</h1>
<Table border="3">


<%


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

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



%>

<Table>
</html>


---------------------------------end
upload.jsp----------------------------------------------------






-----Original Message-----
From: contact@abilsoft.com [mailto:contact@abilsoft.com]
Sent: Thursday, May 15, 2003 3:12 PM
To: Tomcat Users List; matt@wiseley.com
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 http://www.servlets.com/cos/index.html. 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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message