File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet" Watch "Servlet" New topic


Abhijeet Neware

Joined: Mar 28, 2011
Posts: 16
This question is confused me every time so guide me someone please.....
Difference between ServletConfig and ServletContext
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 632

There is only one servletContext per application but there is one ServletConfig per servlet. Hence we write servletContext in application tag of xml file and write servletConfig in servlet tag of xml file.

There are many servletConfig in application but only one ServletContext in an application.

If you want to use a variable through out the application then you have to use servletContext and if you want to use varible only for partivular servlet then use servletConfig.

Life is easy because we write the source code.....
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Please UseAMeaningfulSubjectLine
I agree. Here's the link:
subject: Servlet
It's not a secret anymore!