jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes servlet context and servlet config Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet context and servlet config" Watch "servlet context and servlet config" New topic
Author

servlet context and servlet config

divya anand
Greenhorn

Joined: Oct 28, 2008
Posts: 25
Hi All,

I'm a beginner, learning servlets. Could anyone please explain clearly what a servletContext and servletConfig does?


Thanks,
d86
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

"d86", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

Have you checked the JavaDoc for these classes?
divya anand
Greenhorn

Joined: Oct 28, 2008
Posts: 25



no. i use head first book, but the explanation given for it was not clear to me.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

divya anand wrote:no.

Then it's time to read them.
Kumari Priyanka
Greenhorn

Joined: Dec 29, 2008
Posts: 7
see Divya....head first book is very good...and moreover its clearly written there that servlet context is for the whole web application while servlet config is for a particular servlet. Particular servlet means the servlet you had written for your web application and whose entry is there in the deployment descriptor. You can access the init parameter(deploy time constant parameters) from the servlet context and servlet config object. There are lot many concept...but for that you need to study..... but this is what i can say in nutshell....
Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 119
You see it is very Simple.

ServletConfig is basically used for configuring individual servlet. Si in a nut shell it is used for servlet specific

configuration. That is why you write <init-param> inside the <servlet>tag.It's specific to individual servlet.


ServletContext is more of a Global object.It is global to application object. If you want object to be shared by all

instances (actually thread) of servlets that run in an application you write it in ServletContext. That is why you write

<context-param> tag inside <web-app> tag. Not inside <servlet> in DD.

I hope it has solved the problem.

Read Head First. It's clearly mentioned.


Anil Deshpande
SCJP 1.5, SCWCD 1.5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet context and servlet config