You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tobias Meyer <t-...@gmx.de> on 2001/07/07 15:59:31 UTC

MultipartRequest and oreilly's servlet package

Hi!

I was trying to implement an upload feature using oreilly's
com.oreilly.servlet package. http://www.servlets.com/cos/
(...and NOT using the build-in functions in struts)

The oreilly stuff works great, but when I combine struts and
the oreilly classes I'm getting an IOException 
(Corrupt form data: premature ending) in the oreilly class.

This seems strange to me, does struts somehow "corrupts"
the HttpServletRequest so that it cannot be accessed by 
oreilly's MultipartRequest class?

--
public ActionForward perform(ActionMapping mapping,
                      ActionForm form,
                      HttpServletRequest request,
                      HttpServletResponse response)
	throws IOException, ServletException
{

try {
   MultipartRequest multi = 
	new MultipartRequest(request, ".", 10*1024*1024); // 10MB
...
--

thanks,

Tobias



RE: MultipartRequest and oreilly's servlet package

Posted by Tobias Meyer <t-...@gmx.de>.
Thanks Martin for your great explanation!

I don't want to get that deep into the struts code,
so I will have to use the build-in 
MultipartRequestHandler... :/






Re: MultipartRequest and oreilly's servlet package

Posted by Martin Cooper <ma...@tumbleweed.com>.
By the time your perform() method is called, the input stream has already
been consumed by the Struts multipart handler, so there's nothing left for
the O'Reilly one to read. You'll need to disable the Struts multipart
handler first.

Unfortunately, there isn't a good way to disable the Struts multipart
handler. Although you can specify an alternative handler as an init-param,
that has to implement the MultipartRequestHandler interface, and there's no
way to specify "no handler".

To work around this, you should be able to call setMultipartClass() in
ActionServlet, passing it null for the class name. (I haven't tried this,
but it should work.) The best time to do this would be at initialization
time, which means you would have to extend ActionServlet and override one of
the init* methods (perhaps initUpload itself).

I recently took a different approach to work around some problems with the
Struts multipart handler. Since I already had a bunch of code that was built
around the Struts mechanism, I didn't want to have to change it all, so I
wrote my own implementation of MultipartRequestHandler. I'm using Resin as
my container, which has multipart support, so I layered my handler on top of
Resin's approach and just dropped in my handler as a replacement for the
Struts handler. It seems to work well.

Hope this helps.

--
Martin Cooper


----- Original Message -----
From: "Tobias Meyer" <t-...@gmx.de>
To: <st...@jakarta.apache.org>
Sent: Saturday, July 07, 2001 6:59 AM
Subject: MultipartRequest and oreilly's servlet package


> Hi!
>
> I was trying to implement an upload feature using oreilly's
> com.oreilly.servlet package. http://www.servlets.com/cos/
> (...and NOT using the build-in functions in struts)
>
> The oreilly stuff works great, but when I combine struts and
> the oreilly classes I'm getting an IOException
> (Corrupt form data: premature ending) in the oreilly class.
>
> This seems strange to me, does struts somehow "corrupts"
> the HttpServletRequest so that it cannot be accessed by
> oreilly's MultipartRequest class?
>
> --
> public ActionForward perform(ActionMapping mapping,
>                       ActionForm form,
>                       HttpServletRequest request,
>                       HttpServletResponse response)
> throws IOException, ServletException
> {
>
> try {
>    MultipartRequest multi =
> new MultipartRequest(request, ".", 10*1024*1024); // 10MB
> ...
> --
>
> thanks,
>
> Tobias
>
>
>