[Web-SIG] [server-side] request/response objects

David Fraser davidf at sjsoft.com
Wed Oct 29 00:02:55 EST 2003


Moof wrote:

> Greg Stein wrote:
>
> > When you stop and think about it: *every* request object will have a
> > matching response object. Why have two objects if they come in 
> pairs? You
> > will never see one without the other, and they are intrinsically 
> tied to
> > each other. So why separate them?
>
>
> An example where a separate response object is useful, though this 
> could well be due to lazy programming, or could be circumvented other 
> ways:
>
> I'm currently writing an app in WebKit, and amongst other things, I 
> find myself writing parts of the page, followed by doing some 
> calculations, followed by writing other parts of the page. 
> Alternatively, I find myself validating user input and doing 
> calculations, and then writing the whole page as a result. Either way, 
> if there's an error that occurs somewhere along the line, due to 
> faulty input, I tell the page to forward the request to another 
> servlet that can handle the errors (normally right back to the servlet 
> that generated the form that inputted the faulty data).
>
> It's a bit of a poor man's exception, because Page.forward() doesn't 
> *actually* break out of the current context, so I need to break out 
> manually, either with a break statement or more normally by continuing 
> til an uncaught exception is thrown.
>
> The forward directive will be taken into account as soon as the page 
> ends, and will just delete the current response object and call the 
> forwarded servlet with a new response object which will buffer and 
> eventually send out the data that the servlet eventually generates.
>
> Then again, it could just be lazy programming on my part.
>
> Moof

There's no requirement that just because the API defines a response 
object that is the same as the request object, that you have to use that 
object to build up your response.
The response side of the request object would mainly be used to *write* 
the response back to the client. Since once you have started writing, 
you can't throw it away, it seems to me your situation would be entirely 
the same (you would have your own "response" which you would only write 
back when you wanted to)

David




More information about the Web-SIG mailing list