Newsletter |
Difference between ServletConfig and ServletContext in Java
Servlets » on Feb 2, 2013 { 40 Comments } By Sivateja
Let us see the main differences between ServletConfig and ServletContext, which is very popular interview question as well π
ServletConfig
- ServletConfig available in javax.servlet.*; package
- ServletConfig object is one per servlet class
- Object of ServletConfig will be created during initialization process of the servlet
- This Config object is public to a particular servlet only
- Scope: As long as a servlet is executing, ServletConfig object will be available, it will be destroyed once the servlet execution is completed.
- We should give request explicitly, in order to create ServletConfig object for the first time
- In web.xml – <init-param> tag will be appear under <servlet-class> tag
ServletContext
- ServletContext available in javax.servlet.*; package
- ServletContext object is global to entire web application
- Object of ServletContext will be created at the time of web application deployment
- Scope: As long as web application is executing, ServletContext object will be available, and it will be destroyed once the application is removed from the server.
- ServletContext object will be available even before giving the first request
- In web.xml – <context-param> tag will be appear under <web-app> tag
So finally…….
No. of web applicationsΒ =Β That many number of ServletContext objects [ 1 per web application ]
No. of servlet classes = That many number of ServletConfig objects
Cheers π
β ββ
You Might Also Like
::. About the Author .:: | ||
Comments
40 Responses to “Difference between ServletConfig and ServletContext in Java”
what is flushing mechanism?
Nice and clear !!!
Good explanation…!!
Nice explanation….
I cant understand in deeply….so….
Very nice Explanation .Thank you
Very precise & good explanation Sir…..Thank you:)
Nice one and very helpful π
buddy your explanation is so nice and clear thanks a lot
Nice explanation but it’s better to provide example programs
Nice & Precise.
neat and precise explaination..thanks a lot
plz…plz…!
provide more information about servlet and jsp. frame works spring core,spring mvc
Nice explanation
Nice, but it would be great if you explain with a small examples…
Nice explanation
crisp and clear
Finally, what these two methods will return to the user?
nice and thanks
Good explanation.Thank you!!!
able understand it. Thank you..
do you make servletConfig param values as global param values(servletContext param values)?
Nice explanation
Nice explanation.Thank you!!
its nice and simple to understand can u post the any example of servlet context,servlet config using init,service and destroy method
very clear and very good thanks
Nice nd too good
Every middle class student to understod
Thank you Bosssssssssss
One of the best website for freshers and also for experienced to refer.
Great Job..
nice explaination…. thanks
Very quick understanding, nice!!!!!!
Nice Explaination…………..
Awesome dude..
Nicely written but if there were an example it would quite be easy.Balwan ko aur balwan karo … isse chalaaki nahi, rajneeti kehte hai
very nice and understandable explanation
Very nice
ServletConfig:
1.The Object of ServletConfig is created by the web container for each servlet.
2.The getServletConfig() method of servlet Interface is used to Create ServletConfig object.
3.The object of ServletConfig is created at the Time of Intailization process of servlet.
ServletContext:
1.The Object of ServletContext is created by the web container for each Web Application.
2.The getServletConfig() method of ServletConfig Interface is used to Create ServletContext object.
3.3.The object of ServletContext is created at the Time of deployment of Project or web application.
Informative blog, your all articles are amazing . Thanks for sharing , share some more basic of java servlet.
I really got clarity about this topic..
Thanks
Very well explained in simple language.ππΌ