Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how respone object work?  RSS feed

 
Gajendra Kangokar
Ranch Hand
Posts: 94
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i am unable to understand how line 3 works?
or is out.println(result) printing the result on webpage?
is response.getWriter() taking the result from println?if yes where is it returning the result to?
if container is taking the response from the servlet,how will we come to know(analyse) that from the above code?..

Thank you
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The container takes care of creating the response object and connecting it to the socket that will send the response data. It also creates a buffer so that bytes can be saved up (for example from the Writer), and sent in reasonable size chunks according to the TCP/IP protocol, eventually being received by your browser.

The internal workings of the response is not something you have to worry about.

A response consists of both headers and (usually) a body. Search for "http response" for more details.

Bill
 
Luan Cestari
Ranch Hand
Posts: 172
C++ Redhat Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think what William said is right. I would just give an advice that if you flush and close the object you might get some RuntimeException (e.g. IllegalStateException) (this often occurs when you handle the request like you are doing but with more complex scenario which uses fowards, e.g.).

Regards!
Luan
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!