It's not a secret anymore!*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Servlet Context theoretical doubt : HF book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Servlet Context theoretical doubt : HF book" Watch "Servlet Context theoretical doubt : HF book" New topic
Author

Servlet Context theoretical doubt : HF book

Rahul Sudip Bose
Ranch Hand

Joined: Jan 21, 2011
Posts: 637

I am unable to understand what exactly is servlet context used for ? Can you suggest examples from real-world applications ?
The HF book says "Its a kind of application bulletin-board, where you can put up messages (called attributes) that other parts of the application can access" . Can anyone suggest an example that demonstrates this ? And why would i want to "put up messages (called attributes) that other parts of the application can access" ?

There is a servlet that allows a user to download a jar file. How does it fit into the above explanation ?

here is a part of that servlet code :



PS : please be frank and let me know if this is a silly doubt.


SCJP 6. Learning more now.
Mike Zal
Ranch Hand

Joined: May 04, 2011
Posts: 144

My favorite example of this is a "Contact Us" email address. Suppose the email address is 'contact at domain.org' . It would be a horrible practice to hard hard the email address value into a JSP. If at some future point the address needs to change, you would need to change the hard coded value in every JSP.

Imagine that the following code runs on application start up


This saves the String "contact at domain dot org" to a variable that any part of the application can use. Now instead of hard coding 'contact at domain.org' you can do either of the following
Inside a Servlet

Inside a JSP with Scriptlets

Inside a JSP with EL


OCJP6, OCWCD5
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Great Explanation!


The future belongs to those who believe in the beauty of their dreams.Dream BIG!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Servlet Context theoretical doubt : HF book