Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not clear why the setAttribute() method is part of the ServletRequest interface

 
Souvvik Basu
Ranch Hand
Posts: 96
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the request object's setAttribute() method, we can set the attributes for the jsp page to which we can finally write out the response. We do this using the requestDispatcher object.
What I dont understand is, the attributes being printed on the next jsp page is actually a part of the response. Then why is the setAttribute() method in the ServletRequest interface, and not the ServletResponse interface?
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3165
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Attributes, Parameters are a way of passing some information to the Server- So they are part of the HttpServletRequest. Response is what the server sends back to the client- and this would involve- the result from the server which are part of HttpServletResponse.
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Souvvik Basu wrote:Then why is the setAttribute() method in the ServletRequest interface, and not the ServletResponse interface?
Because of the following difference setAttribute() is part of ServletRequest interface.

For ServletRequest
Java EE Docs wrote:Defines an object to provide client request information to a servlet


For ServletResponse
Java EE Docs wrote:Defines an object to assist a servlet in sending a response to the client
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, parameters are passed from the client side...

But attributes are set at the servlet side.

Request attributes are nothing but the message shared between two servlets and is not visible to the end client... mainly used in Request Dispatching...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic