aspose file tools
The moose likes Servlets and the fly likes apache.commons.FileUpload: parseRequest()-Method changes Request-Object? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "apache.commons.FileUpload: parseRequest()-Method changes Request-Object?" Watch "apache.commons.FileUpload: parseRequest()-Method changes Request-Object?" New topic
Author

apache.commons.FileUpload: parseRequest()-Method changes Request-Object?

Daniel Haupt
Greenhorn

Joined: May 22, 2006
Posts: 13
Hi folks,

i've got a problem within my struts application. I've added a filter which is triggered before the request is taken to the struts ActionForm.

I've got a multipart/form-data html formular, so I use apache.commons.FileUpload to parse the request and get my specific request parameter by using the parseRequest(HttpServletRequest)-method of ServletFileUpload class.

By doing filter.chain() I continue processing, but now I've got a nullpointer in my ActionForm because there are no more parameters in the HttpServletRequest-Object.

Is parseRequest() changing my object in any way? Are there any alternatives if I just want to get a parameter value (html-input) inside of my filter?

Thanks for your help

Daniel
[ October 20, 2008: Message edited by: Bear Bibeault ]
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3041
    
    4

Originally posted by Daniel Haupt:
Hi folks,

i've got a problem within my struts application. I've added a filter which is triggered before the request is taken to the struts ActionForm.

I've got a multipart/form-data html formular, so I use apache.commons.FileUpload to parse the request and get my specific request parameter by using the parseRequest(HttpServletRequest)-method of ServletFileUpload class.

By doing filter.chain() I continue processing, but now I've got a nullpointer in my ActionForm because there are no more parameters in the HttpServletRequest-Object.

Is parseRequest() changing my object in any way? Are there any alternatives if I just want to get a parameter value (html-input) inside of my filter?

Thanks for your help

Daniel


What do you mean by 'there are no more parameters'?

One option would be to write an HttpServletRequestWrapper implementation that takes the list of FileItems created by the parseRequest method and make them visible as parameters to all callers. You would then wrap the original request and pass the new wrapper on to filter.doChain().



- Edit - Stupid smilies...
[ October 20, 2008: Message edited by: Steve Luke ]

Steve
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56233
    
  13

The getParameter() methods should not be used when submitting a multi-part form. The whole purpose of the commons library is to parse the multi-part request for you. So yes, it changes the request by reading its input stream so it can gather the uploaded file(s) as well as the other request parameters.

Use the API of the upload package to obtain the values. No need for a wrapper.
[ October 20, 2008: Message edited by: Bear Bibeault ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: apache.commons.FileUpload: parseRequest()-Method changes Request-Object?
 
Similar Threads
call servlet with multipart, apache.commons.fileupload how ?
Dynamic iterate checkbox
apache.commons.fileupload - Browser blocks ajax requests
A buildDTO() in Action or in ActionForm ???
Summary of Struts, by Struts newbie