tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Sinclair <>
Subject Problem with RequestDispatcher.forward() and mutlipart/form-data request
Date Fri, 02 Mar 2001 07:12:23 GMT
I have a very strange problem with the RequestDispatcher.forward()
command. I am trying to forward to a very simple JSP from within
a servlet after handling a request of type="multipart/form-data".

I am using the following HTML to attempt to upload a file:

  <form enctype="multipart/form-data" name="FileUploadForm" action="/test/testfu" method="post">
    Please specify file for upload:<br>
    <INPUT TYPE="file" NAME="file_to_upload"><br>
    <INPUT TYPE="submit" VALUE="Upload">

and handling it within the servlet using the MultipartRequest
object from the "com.oreilly.servlet" package of servlet utilities.

  ... service(... req, ... res) throws IOException
      ArrayList        finfos = new ArrayList();
      MultipartRequest multi  = new MultipartRequest(req, ".");
      Enumeration      files  = multi.getFileNames();

      while (files.hasMoreElements())
        String name     = (String)files.nextElement();
        String filename = multi.getFilesystemName(name);
        String type     = multi.getContentType(name);
        File   f        = multi.getFile(name);
        if (f!=null)
          String[] finfo  = new String[] { name, filename, type, ""+f.length() };
      req.setAttribute("finfos", finfos);
      System.out.print("Forwarding ... ");
      RequestDispatcher rd = getServletContext()
      rd.include(req, res);
    catch (IOException e)
      System.out.print("Error ... ");
        RequestDispatcher rd = getServletContext()
        rd.forward(req, res);
      catch (Exception ignore)
        System.out.println("Error with inner forward.");
    catch (Exception ignore)
      System.out.println("Error with outer forward.");

The main problem is that the forward() call (right after the 
1st IOException has been thrown) results in some very strange
behavior. As far as the servlet is concerned, the forward 
call seems to work, ie there is no exception thrown. But
the forwarded-to jsp is never called up. The browser (IE5.5)
presents an error page: 

  "The page cannot be displayed. 
  The page you are looking for is currently unavailable. The 
  Web site might be experiencing technical difficulties, or 
  you may need to adjust your browser settings."

The really wierd thing is that this error only happens when
the file that is uploaded is of a certain size. If the file
is small, there is no problems, but if the file is large, then
the forward breaks. Interestingly, if I just comment out the
lines that instantiate the MultipartRequest and query it for
the uploaded file and go straight into the forward, it will
allways fail, no matter how big the uploaded file is.

I think (and this is just a guess) that there is something odd
going on with the forward() call when the request is of content
type "multipart/form-data". Although, I am at a complete loss as
to how the content type of the request, has anything to do with
the response.

Of course (as usual with technical problems that I seem to get
myself into) I am well prepared to have fundamentally missed

Any help would be much appreciated.


View raw message