What is the Difference between ServletConfig and ServletContext.?
ServletConfig:
public interface ServletConfig
ServletConfig encapsulates servlet configuration and gives access to the application (servlet context) object. Servlet initialization parameters appear in the servlet configuration file. Each servlet class may have several different servlet instances, one for each servlet parameters:
Example:
ServletContext:
public interface ServletContext
ServletContexts encapsulate applications. Applications are generalized virtual hosts; a URL prefix defines a distinct application. So /myapp and /yourapp could define different applications. As a degenerate case, each virtual host has its own ServletContext.
Example:
ServletConfig:
public interface ServletConfig
ServletConfig encapsulates servlet configuration and gives access to the application (servlet context) object. Servlet initialization parameters appear in the servlet configuration file. Each servlet class may have several different servlet instances, one for each servlet parameters:
- One ServletConfig per servlet
- It is used to pass deploy-time info to servlet and configured in the deployment descriptor file.
- it is used to access ServletContext
- It is within the Servlet element in Deployment descriptor.
- It is accessed by using getServletConfig().getInitParameter("myname");
- It is available only to the servlet in which init-param is configured.
Example:
ServletContext:
public interface ServletContext
ServletContexts encapsulate applications. Applications are generalized virtual hosts; a URL prefix defines a distinct application. So /myapp and /yourapp could define different applications. As a degenerate case, each virtual host has its own ServletContext.
- It returns the current context of a web application running in a particular JVM..
- If the web application is distributed,it is one per JVM.
- It is used to access the elements configured in deployment descriptor.
- It is accessed by using getServletContext().getInitParameter("myname");
- It is available to any servlet or jsp that is part of web application.
Example:
This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you. Kopar at Newton Kampong Java Road
ReplyDeleteThus, with the above features, Python training can very well act as a mentoring course to freshers. unindent does not match any outer indentation level python
ReplyDelete