The servletconfig object refers to the single servlet whereas
servletcontext object refers to the whole web application
. … That is, you can pass initialization parameters to the servlet using the web. xml deployment descriptor. For understanding, this is similar to a constructor in a java class.
What do you mean by ServletContext?
javax.servlet. Interface ServletContext. public interface ServletContext.
Defines a set of methods that a servlet uses to communicate with its servlet container
, for example, to get the MIME type of a file, dispatch requests, or write to a log file. There is one context per “web application” per Java Virtual Machine.
What are the differences between ServletContext vs ServletConfig?
ServletContext object is obtained by getServletContext() method. Each servlet has got its own ServletConfig object. ServletContext object is only one and used by different servlets of the application. Use ServletConfig when only
one servlet needs information shared by it
.
In which package ServletConfig and ServletContext interfaces are present?
1.2.
ServletContext is an interface from
the javax. servlet package
and its object can be obtained from the getServletContext() method of the ServletContext i.e.
What does ServletConfig interface do?
An object of ServletConfig is created by the web container for each servlet. This object can be
used to get configuration information from web.
xml file, we don’t need to change the servlet. …
What is JSP life cycle?
A JSP life cycle is defined as
the process from its creation till the destruction
. This is similar to a servlet life cycle with an additional step which is required to compile a JSP into servlet.
What is servlet config and ServletContext?
The ServletConfig parameters are
specified for a particular servlet
and are unknown to other servlets. It is used for intializing purposes. The ServletContext parameters are specified for an entire application outside of any particular servlet and are available to all the servlets within that application.
What is the use of ServletContext?
Interface ServletContext. Defines a set of methods that
a servlet uses to communicate with its servlet container
, for example, to get the MIME type of a file, dispatch requests, or write to a log file. There is one context per “web application” per Java Virtual Machine.
How many ServletContext is created for an application?
There is only
one ServletContext object
per web application. If any information is shared to many servlet, it is better to provide it from the web.
Which method is called when client request comes?
The web server calls
the service() method
to handle requests coming from the client( web browsers) and to send response back to the client. This method determines the type of Http request (GET, POST, PUT, DELETE, etc.) . This method also calls various other methods such as doGet(), doPost(), doPut(), doDelete(), etc.
Which packages represent interfaces and classes for?
servlet. http packages
represent interfaces and classes for servlet api. The javax. servlet package contains many interfaces and classes that are used by the servlet or web container.
Which method in session tracking is used?
There are four techniques used in Session tracking:
Cookies
.
Hidden Form Field
.
URL Rewriting
.
Which application is instance of which class?
Application is instance of which class? Explanation: Application object is wrapper around the ServletContext object and it is an instance of a
javax. servlet. ServletContext object
.
What are valid methods for HttpSessionListener interface?
- public void sessionCreated(HttpSessionEvent e): is invoked when session object is created.
- public void sessionDestroyed(ServletContextEvent e): is invoked when session is invalidated.
What are initialization parameters in servlets?
Initialization parameters are
stored as key value pairs
. They are included in web. … The key is specified using the param-name tags and value is specified using the param-value tags. Servlet initialization parameters are retrieved by using the ServletConfig object.
How many methods are common in ServletConfig?
Methods of ServletConfig interface
public Enumeration getInitParameterNames
(): Returns an enumeration of all the parameter names. public String getServletName(): Returns the name of the servlet instance. public ServletContext getServletContext(): Returns an object of ServletContext.