Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpServletRequestWrapper

 
muthulingam Jayakanthan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can some one please send me small note about HttpServletRequestWrapper from the Head First Book or anywhere else. I have only Servlet Spec with me. But there is not much info about that.
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by muthulingam Jayakanthan:
can some one please send me small note about HttpServletRequestWrapper from the Head First Book or anywhere else. I have only Servlet Spec with me. But there is not much info about that.


The wrapper classes related to ServletRequest, ServletResponse, HttpServletRequest and HttpServletResponse are used when you want to expose to your clients an 'enhanced' version of the above objects. This is possible because a wrapper delegates to the 'official' object all the standard functionalities. This is possible because a wrapper normally should accept in its constructor an instance of the 'official' object. So it becomes easy for a wrapper having a reference to an instance of a certain class, and implementing its same interface, to invoke the 'official' object's methods (acting, that's it, as a wrapper). However, by extending a wrapper class, you can override only those methods for which you want to provide special functionalities. Then, from within the class from which you want to create the 'empowered' object, you will create an instance of the class extending the wrapper and you will pass this instance to whichever client of your empowered object.

The wrapper class is an implementation of the Decorator/Wrapper pattern.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic