ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Java Related >> Java J2EE >> Servlets
 
 


 

 
 Core Java interview questions  Core Java Interview Questions (1722)
 Advanced Java interview questions  Advanced Java Interview Questions (331)
 Swing interview questions  Swing Interview Questions (44)
 EJB interview questions  EJB Interview Questions (134)
 Servlets interview questions  Servlets Interview Questions (255)
 Struts interview questions  Struts Interview Questions (196)
 JDBC interview questions  JDBC Interview Questions (187)
 JMS interview questions  JMS Interview Questions (9)
 SunOne interview questions  SunOne Interview Questions (3)
 J2EE interview questions  J2EE Interview Questions (71)
 Weblogic interview questions  Weblogic Interview Questions (147)
 Websphere interview questions  Websphere Interview Questions (14)
 Java Networking interview questions  Java Networking Interview Questions (20)
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions (87)
Question
What is ServletContext() and what is its use?
 Question Submitted By :: Servlets
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
One Servlet Context object will be created by the container
for one webapplication. That means all servlets can have a
scope to acess that context object. for example, let us
assume there 5 servlets are there in u r web application,
if u want to share same data to all servlets then we can
share that data using servlet context, because every
servlet can have interaction with that application
environment...
 
Is This Answer Correct ?    170 Yes 22 No
Shiva
 
Answer
# 2
Assume that ServletContext is shared momeroy for all
servelts which are existed in a web application,

we can place an object on to the servletcontext, and that
can uses all other servlets which are exited in the web
application.
 
Is This Answer Correct ?    146 Yes 27 No
Anjan
 
 
 
Answer
# 3
1. ServletContext is a window by which a Servlet instance see its environment.

2. ServletContext defines some methods that a Servlet instance can use to communicate with Servlet Container. E.g. To dispatch request, Writing to a log file etc.

3. Servlet Container pass the ServletConfig object to the Servlet instance when calling init(ServletConfig config) method. ServletContext instance reference exist inside the ServletConfig object.

4. Each Web application has only one ServletContext instance. So its a singleton object. If an Servlet Container deploys multiple Apps, each App have its own ServletContext.
 
Is This Answer Correct ?    96 Yes 7 No
Asif Shahzad
 
Answer
# 4
if u want to use any data which is common for all use and
common to all servlet ,that data can be specified as context
parameters in the web.xml as follows.
<context-param>
<param-name>city</param-name>
<param-value>bangalore</param-value>
</context-param>
web container collects data from web.xml and stores that in
servlet context objects as context parameters.
As a developer,you can collect that data form context object
as follows.
String ci=context.getIntParameters("city").
All the servlets will have only one servlet context object
and can be shared with all servlets running in the container.
i.e: one web application will have one servletcontext object.
 
Is This Answer Correct ?    52 Yes 2 No
Shyam
 
Answer
# 5
servletcontext is an object which contains the information
regarding all the servlets that are used in web application.
when ever user first do the deployment of the web
application on the server the web container instantiate a
servlet context object.the information in the servlet
context object is also passed to init method.
 
Is This Answer Correct ?    50 Yes 20 No
A,srinivas Rao
 
Answer
# 6
Data saved in a ServletContext scope is shared by all
servlets and JSPs in the context. The data stored in the servlet
context is destroyed when the servlet context is destroyed.
//save and get an application-scoped value
getServletContext().setAttribute(“application-value”,
“shopping-app”);
value = getServletContext().getAttribute(“application-value”);
 
Is This Answer Correct ?    27 Yes 9 No
Telo
 
Answer
# 7
ServletContext is called web application there would be one servlet context for entire web applicationthe .servlet context is used to get the context parameters specified in web.xml and also get the information of servlet engineand also request dispatcher object. 
Is This Answer Correct ?    13 Yes 13 No
Srikanth
 
Answer
# 8
as soon as the java web application is
deployed into web container ,the first
object that container create is
servletcontext
This object is only one per web application
Every web component of web application
share this unique object
 
Is This Answer Correct ?    0 Yes 0 No
Ranjit
 
Answer
# 9
A servlete context is the directory in which the servlet
are deployed in the web server. Servlet that are executing
in the same server belong to the same context.
 
Is This Answer Correct ?    18 Yes 31 No
Rahul Kumar
 

 
 
 
Other Servlets Interview Questions
 
  Question Asked @ Answers
 
What is a Session Id?   1
hi.... i have problem in running of servlet. i am using Tomcat server in my pc.. The problem is when i am click on strat it will display like below FAIL - Application at context path /first could not be started.. How i can slove the problem.. help plz   3
Is the init(ServletConfig sc) throws IOException or not?   3
What is session variable in servlets?   1
In servlets, Why do we need both GET and POST method implementations? IBM 3
Hi guys.. Well can u tell me that why there is need of "init()" , i mean why can not we initialize the servlet object with the help of constructors? Thank you.   7
If we disable cookies in our web page, what will happen? Zensar 6
How to set a cookie that is persisted only for the duration fo the clients session?   1
How do you pass the data from one servlet to another servlet? HCL 11
What is context switching?   4
program for RequestDispatcher in servlets? Wipro 3
what is servlet life cycle? Inforica 3
 
For more Servlets Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright © 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com