Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the need of response object  RSS feed

 
vysh sri
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inspite of not returning anything, what is the purpose of response object in servlet? I have typically used or heard of only response.sendRedirect()
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at the API for HttpServletResponse? Redirect (sendRedirect) is just one feature, others include:
*working with cookies (addCookie)
*URL encoding (encodeURL)
*working with headers (eg xxxHeader)
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In best object oriented fashion, the response object hides all the fiddly little details involved in communicating with the client.

Since creating and managing response objects is the responsibility of the servlet container, container architects can perform various optimizations - such as a pool of reusable response object - without disturbing the programmer of applications.

Bill
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vysh sri wrote:Inspite of not returning anything, what is the purpose of response object in servlet?


But the vast majority of requests do actually return something. Normally there's some kind of data (often HTML but sometimes other types) and there are headers which can be used for a variety of things.
 
Albert John Thomas
Greenhorn
Posts: 2
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Internally the JSP pages get converted to Servlets , and the with the help of rresponse objects , content types,..etc. are set.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!