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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
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: 4179
    
  21

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: 61054
    
  66

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Don't get me started about those stupid light bulbs.
 
subject: apache.commons.FileUpload: parseRequest()-Method changes Request-Object?