Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Dangerous to forward using dispatcher w/ uploaded files???

Reply
Thread Tools

Dangerous to forward using dispatcher w/ uploaded files???

 
 
Saad Malik
Guest
Posts: n/a
 
      07-05-2004
Hi Guys/Gals,
I know that when you upload files in JSP/Servlets you have to set the
form method to post and type to form-data.

Since the method is POST, the file will be attached after the request
headers of the client request.

And if that is true, then is it also true that you SHOULD never
forward to servlets/jsp (using requestDispatcher) since there could be
a potential 100's of mb in the body of the request that has to be
moved with the original request to the new servlet/jsp?

If this is not the case, can someone please explain why it is not?

THanks.

Saad.
 
Reply With Quote
 
 
 
 
Murray
Guest
Posts: n/a
 
      07-05-2004

"Saad Malik" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> Hi Guys/Gals,
> I know that when you upload files in JSP/Servlets you have to set the
> form method to post and type to form-data.
>
> Since the method is POST, the file will be attached after the request
> headers of the client request.
>
> And if that is true, then is it also true that you SHOULD never
> forward to servlets/jsp (using requestDispatcher) since there could be
> a potential 100's of mb in the body of the request that has to be
> moved with the original request to the new servlet/jsp?
>
> If this is not the case, can someone please explain why it is not?
>
> THanks.
>
> Saad.


Most of what you have said is true, i.e. the file is sent as POST data and
will be forwarded as part of the request. However, it should have no/little
impact on performance since forwards using requestDispatcher are done
internally. It doesn't go back to the client, it doesn't copy/recreate a new
request, it should simply pass the existing request by reference to the
servlet you're forwarding to. At least that's how it works for application
servers that I've used.

There may be one benefit from using sendRedirect instead of forward() .. the
POSTed data MAY be eligible for garbage collection slightly sooner. But this
would only be an issue if memory is very scarce and/or the servlet you're
forwarding to takes a long time to complete.


 
Reply With Quote
 
 
 
 
Saad Malik
Guest
Posts: n/a
 
      07-05-2004
> There may be one benefit from using sendRedirect instead of forward() .. the
> POSTed data MAY be eligible for garbage collection slightly sooner. But this
> would only be an issue if memory is very scarce and/or the servlet you're
> forwarding to takes a long time to complete.


Thanks for responding Murray. I didn't even think about that you pass
request and response object as a reference to another servlet with
dispatcher.

However you made me even more confused now

response.sendRedirect() sets a status code to 303 something (I think)
and also sends back a header to the client to connect to another URL.
However, new REQUEST & Response ARE generated since they are not
passed to the new servlet/jsp.

On top of that, doesn't sendRedirect not send query data even of a get
request... unless you specically append it e.g. sendRedirect(afs.jsp?
+ "fsf=dfs");

Making it is impossible to redirect a request that was tranmitted with
post using sendRedirect()... right?

So the only solution left is RequestDispatcher..

Just wondering if i'm wrong or right?
 
Reply With Quote
 
John C. Bollinger
Guest
Posts: n/a
 
      07-05-2004
Saad Malik wrote:

>>There may be one benefit from using sendRedirect instead of forward() .. the
>>POSTed data MAY be eligible for garbage collection slightly sooner. But this
>>would only be an issue if memory is very scarce and/or the servlet you're
>>forwarding to takes a long time to complete.

>
>
> Thanks for responding Murray. I didn't even think about that you pass
> request and response object as a reference to another servlet with
> dispatcher.
>
> However you made me even more confused now
>
> response.sendRedirect() sets a status code to 303 something (I think)
> and also sends back a header to the client to connect to another URL.


It is probably clearest (and most consistent with the HTTP specs) to
characterize this as the server sending a response with status code 303.
That might be called a "redirect response", or, less formally, simply a
"redirect".

> However, new REQUEST & Response ARE generated since they are not
> passed to the new servlet/jsp.


Yes, an HTTP user agent (such as a web browser) will typically handle a
redirect response by generating a new request for the specified
alternative URI. Sending a redirect thus causes a second HTTP
round-trip, which is the one of the fundamental differences between
redirecting and forwarding with a RequestDispatcher.

> On top of that, doesn't sendRedirect not send query data even of a get
> request... unless you specically append it e.g. sendRedirect(afs.jsp?
> + "fsf=dfs");


This is probably correct, and it is in any case the appropriate behavior.

> Making it is impossible to redirect a request that was tranmitted with
> post using sendRedirect()... right?


That depends on how the user agent handles the situation. I don't
offhand know what the more common ones do, but conceivably they might
repost the data.

> So the only solution left is RequestDispatcher..


You say that as if it's a bad thing. If you're talking about a
situation where large posts are being handled by your application then a
RequestDispatcher.forward() is exactly what you want. In fact, in many
cases it is exactly what you want. In most others the underlying
problem is that HTTP does not support the functionality you want; Java
has no control over that.


John Bollinger
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Derrick Pallas' ruby fcgi dispatcher Kai Krakow Ruby 3 05-15-2008 05:49 PM
Use link to forward Session entries instead of Request Dispatcher francan00@yahoo.com Java 2 09-13-2007 11:55 PM
JSP dispatcher.forward and # => NullPointerException Tony Murphy Java 0 02-16-2004 04:57 PM
[jboss+jetty] dispatcher.forward giving StackOverflowError Maciek Zywno Java 0 09-03-2003 04:19 PM
Virus-Scanning uploaded files uploaded? Matt G ASP .Net 1 08-22-2003 05:44 AM



Advertisments