aspose file tools*
The moose likes Servlets and the fly likes Beginner in servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Beginner in servlets" Watch "Beginner in servlets" New topic
Author

Beginner in servlets

Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
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

Joined: Jul 12, 2002
Posts: 1075
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

Joined: Jan 19, 2004
Posts: 125
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

Joined: May 30, 2002
Posts: 1400
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).


- Varun
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Beginner in servlets