Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Beginner in servlets

 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mike London
Ranch Hand
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet context will let you do what you want. It has application scope.
Check out coreservlets.com for some good background info.
-- Mike
 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lucky Singh:

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?

Your first question is the answer to your second question.
(And offcourse that is one among the many uses of Servlet context).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic