• 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:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Servlet Context theoretical doubt : HF book

 
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 144
Oracle Fedora Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great Explanation!
 
The airline is called "Virgin"? Don't you want a plane to go all the way? This tiny ad will go all the way:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic