Hi

I have an struts application which does the
authorisation in filters. Authorisation is done using
the request.getParameter("menu"). 

This filter works very fine But fails when the the
request is of enctype="multipart/form-data". i.e when
i am using the file upload in the page. 

To solve this i used the commons-fileupload to get the
Parameter. Now again the parameter is available at
filter, but the request fails at Action of Struts.

Now how do i convert the request back to the original
form. If you could get me the code, it would be highly
appreciated.

My parsing code:

      int contentLength = request.getContentLength();
      // Copy the request's input stream. 
      final ServletInputStream bis =
request.getInputStream();
      final BufferedOutputStream bos;
      final Object bodyData;
      if (contentLength > 50000)
      {
        // Use a disk file for storing the body data. 
        bodyDataFile = File.createTempFile("body-",
".data");
        bodyDataFile.deleteOnExit();
        final FileOutputStream fos = new
FileOutputStream(bodyDataFile);
        bos = new BufferedOutputStream(fos);
        bodyData = bodyDataFile;
      }
      else
      {
        // Use a byte array for storing the body data.

        final ByteArrayOutputStream baos = new
ByteArrayOutputStream();
        bos = new BufferedOutputStream(baos);
        bodyData = baos;
      }
      final int BUFFER_SIZE = 10240;
      byte[] buffer = new byte[BUFFER_SIZE];
      int toBeCopied = contentLength;
      while (toBeCopied > 0)
      {
        int read = bis.read(buffer, 0,
Math.min(BUFFER_SIZE, toBeCopied));
        bos.write(buffer, 0, read);
        toBeCopied -= read;
      }
      bis.close();
      bos.close();

      // Wrap the request in a
FileUploadHttpServletRequest for further processing. 
      chain.doFilter(new
FileUploadHttpServletRequest((HttpServletRequest)
request, bodyData), response);

Thanks
Vijaya

________________________________________________________________________
Yahoo! India Careers: Over 65,000 jobs online
Go to: http://yahoo.naukri.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to