This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
What is the use of ServletContext in servlets? What can I use in servlets which helps all servelts in an application to use a particular object? Say, I have an object abc which is an instance of the class ABC. The class ABC is in the lib directory. I have created an instance of ABC in servlet1, ---initialized it. What do I do in servlet1 to enable servlet2, servlet3 and servlet4 all access the abc object? And while retrieving abc in servlet2, servlet3 and servlet4, what will the piece of code look like?
The servlet context will let you do what you want. It has application scope. Check out coreservlets.com for some good background info. -- Mike
Joined: Jan 19, 2004
Thanks Mike. But can you give me 3-4 lines of code snippets (in servlet1 and servlet2)for the problem I mentioned so that it would help me get going? I can then read up accordingly and code. I have developed a few servlets before so not entirely a new programmer but yeah, not very experienced either.