Thursday 19 September 2013

pageContext object

pageContext object


  • Till now we discussed all the different ways we can share data between these applications , between the jsp pages. And we know that : first is page, page level, which is restricted to that jsp page only not even request
  • The next level we have : request object: that is request level, and the next level we have session level which comprises of a number of requests and ultimately we have application level which covered whole application , so basically application object covers all the jsp and servlets within the application .
  • Here from bottom to top, Im going from least visible to most visible object , least visible in terms of scope, most visible in terms of scope.
  • So lets say that in my servlet i store the value in the request object, but in the jsp im trying to retrieve the same value from the session object, will I get that value if I set it as request in session level in my jsp ? answer is "no", because if I set the value attribute value at request level in my jsp as well as I have to retrieve that value at the request level . If I set it as request level I have to retrieve it in request level. If i set it is as session level , i have to retrieve it at session level only , I can not simply set it in request and try to retrieve from that value from session level. So for that reason to avoid certain confusion we have the pageContext object.
  • pageContext implicit object is a convenient object which is available in jsp. Lets say that you saved the value in request object , in jsp you really know whether you have saved it in session or request level. So you dont know at which scope you saved , so when you use the pageContext object, basically try to retrieve at the page level first, if it does not retrieve in page level it goes and check at the request level , if it does not get at the request level, it goes to check at the session level to get the value, if pageContext object does not get the value at the session  level, it goes to application level to get the value.
  • So basically when you use the pageContext object it is going to check each and every level starting from least visible to most visible level , if at all match found in any of the scope, it is going to give you the value.
  • So in this case you dont have really worry in jsp, this particular attribute is set at session level, or request level or not? 


No comments:

Post a Comment