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:
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteJava Training in Chennai Core Java Training in Chennai Core Java Training in Chennai
Java Online Training Java Online Training Core Java 8 Training in Chennai java 8 online training JavaEE Training in Chennai Java EE Training in Chennai
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
ReplyDeleteWow, this is fascinating reading. I am glad I found this and got to read it. Great job on this content. I liked it a lot. Thanks for the great and unique info. Europa-Road targonca szállítás Debrecen
ReplyDelete