This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 4167
    
  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: 60783
    
  65

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: apache.commons.FileUpload: parseRequest()-Method changes Request-Object?
 
Similar Threads
A buildDTO() in Action or in ActionForm ???
apache.commons.fileupload - Browser blocks ajax requests
Summary of Struts, by Struts newbie
call servlet with multipart, apache.commons.fileupload how ?
Dynamic iterate checkbox