Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
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?
 
Bartender
Posts: 3185
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.
 
Ranch Hand
Posts: 811
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

 
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
Boost this thread!