Posted on 2006-05-02
Medium Priority
Last Modified: 2010-04-01
Difference between context and config object in servlet.
suppose i want to share 1 variable into 5 servlets.

how could i have done through coding.

could you explain need for config object through coding
  • 2
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16584605

Accepted Solution

arun_kuttz earned 500 total points
ID: 16584691
A servlet context is an object shared by all applications deployed in that container.. for ur requirement, u can use the servletContext object to gain access to variable to be shared across differect servlets (in ur case 5)..

u must have the following snippet in ur web.xml..


this can be accessed by using ServletContext object (which is obtained from the ServletConfig object) like so..


As for the ServletConfig, it is specific to a particular Servlet, and u gain accsss to any initialPrarmeter variable u specify in the <servlet> </servlet> tag of the web.xml like so :


and u access it using the config object, thats passed to the service method of the servlet.. like so



Author Comment

by:Manikandan Thiagarajan
ID: 16584962
what is the need for config object there.

could i access that variable by context object only

Expert Comment

ID: 16585027
> what is the need for config object there.

u need the config object to get acces to the param1 variable..

> could i access that variable by context object only

u cannot access param1 using context object.. u need the config object (since it is specific to THAT servlet)
while the var1 variable can be accessed by all servlets/JSPs using the context object (in servlets, u get the ServletContext object using the config object.. like iv showen u in the above code... in JSPs, u can access the Context object by using the implicit "application" object.


Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why WooCommerce is one of the majorly favored choices when it comes to having an eCommerce store. This article will acquaint you with some reasons that I believe make it one of the best eCommerce platforms available.
These seven tips can help you create an extraordinary website, one that captivates audiences and has them wanting to return regularly for more. Keep reading to find out what your site is missing and what you need to add!
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question