Monday, March 7, 2011

Chapter 13: Web Application Scope

In the previous Chapters we saw what the HTTP Request object is and how to read stuff from it. In this chapter, we are going to discuss a very important topic. “Scope” – Yes, the Web Application Scope. It is just like basic java programming where you can or cannot see a particular variable depending on its visibility. In Web parlance, the scope of an object defines how long it exists and how you can access it.

So, lets get started!!!


For the exam, you need to worry about 3 different scopes. They are:
• Request
• Session &
• Application

The scope would play an important part of any web application.
Let us look at the details of these 3 Scopes.

Scope Accessibility Lifetime
Request Current, included, or forwarded pages Until the response is returned to the user.
Session All requests from same browser within session timeout Until session timeout or session ID invalidated (such as user quits browser).
Application All request to same Web application Life of container or explicitly killed (such as container administration action).
You know that you can set and retrieve attributes (objects) in the request or the session or to the context. So, the purpose of this chapter is to let us identify what attribute is accessible where.

For ex: if you use the request.setAttribute(), you will be able to access it only until this request is alive. Once the request is complete, you will no longer be able to read the attribute that you just set into the request.

But, if you set an attribute into the session you will be able to read it across multiple requests. Similarly if you use the context, you will be able to read it across multiple sessions.

Exam Trivia:
Request is the least available whereas a session is a bit more available and the context is globally available. But, it is not advisable to put all your stuff into the context. Keep only information that you would need across all the users of the website in the context. Keep information that you would need as long as a user is browsing (say his login info) in the session and page specific information in the request.

Dont worry if we did not cover the details of the request, scope or the context because, that is exactly what the subsequent chapters are going to do!!!

Previous Chapter: Chapter 12 - Retrieving HTTP Request Header Information

Next Chapter: Chapter 14 - The Request Object

No comments:

Post a Comment

© 2013 by All rights reserved. No part of this blog or its contents may be reproduced or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission of the Author.