Hi all,

I have implemented a simple upload functionality using the struts framework
(FormFile, etc...), it works well.
But now I'd like to be able to cancel the upload of a file if the file is
larger than a given size, only for this specific action. When I say 'cancel'
I mean have my servlet stop uploading the file if it's too big and return a
response immediately (same input page with an error message).

I am running in a few problems when I try to do this:

- Where can/should I put the code to do this? Adding such logic in the
Action or the FormBean doesn't work since the file is already downloaded
before the perform or validate methods are called...I could put such code in
the doPost method of the actionServlet but it seems quite ugly to me (I
would need to get the action name from the uri and compare it with the
action name for which I want this logic to be applied,...doesn't fit very
well in the struts framework).
So is the correct approach to develop a custom multipartRequest handler?
Where can I find documentation/examples about this?


- I have tried to implement such upload cancellation logic in a 'regular'
servlet (not using struts), but was not successful.

I have put the simple following lines in the doPost method of the servlet
(the code forwards to another uri if the request content is too big). For
some reasons I do not know, the forward fails, the browser shows an error
page instead.
I have read that some web servers require multipart forms request stream to
be entirely read...Is that the reason why this doesn't work? (I am using
Resin2.1.1.). Curiously the forward works fine for non-multipart forms and
multipart forms with 'small' content so I am a bit confused.


        String uri=request.getRequestURI();

        //get the action name, if the action name is 'addtrack' and the
content size if >20Mb approx, then forward to another url.        
        if (uri.equals("/addtrack.do"))
        {
                  if (request.getContentLength() > 20000000)
                  {
                                try{
                                System.out.println("file too big,
forwarding");
 
request.getRequestDispatcher("/account/logon.xtp").forward(request,response)
;
                                return;

                                }
                                catch(Exception e)
                                {
                                System.out.println(e.toString());
                                }
                        }
                    else
                        {
 
request.getRequestDispatcher("/register/intro.xtp").forward(request,response
);
                                return;

                        }
        }
 

Thanks for any help.


Laurent






Reply via email to