
Difference between ServletConfig and ServletContext.
- ServletConfig is used to get configuration for a single servlet.
- ServletContext is used to set and get configuration for the whole web application.
- ServletContext has setAttribute (), getAttribute () and removeAttribute () method, these methods can be used to share or remove object between servlet in whole web application.
What is servletconfig object in servlet?
ServletConfig is used to read servlet configuration data in web.xml. Web container will create one ServletConfig instance for each servlet. The advantage of using this object is that you can make your servlet variable’s value parameterized.
What is the scope of servletcontext?
Scope: As long as web application is executing, ServletContext object will be available, and it will be destroyed once the application is removed from the server. So finally…….
What is the use of tag in servlet config?
tag since it was for the whole application.> Within the Servlet tag you set the value for a Servlet paramter called "About the Servlet". So whenever you do getServletConfig().getInitParamter("About the Servlet") you will get a string "This Servlet gives you a list of colors to select from".
How to initialize a single servlet using servletconfig?
ServletConfig is implemented by the servlet container to initialize a single servlet using init (). 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 is the difference between ServletContext and ServletConfig object?
ServletConfig is used for sharing init parameters specific to a servlet while ServletContext is for sharing init parameters within any Servlet within a web application.
What is ServletConfig and ServletContext with example?
ServletConfig is an object containing some initial parameters or configuration information created by Servlet Container and passed to the servlet during initialization. ServletConfig is for a particular servlet, that means one should store servlet specific information in web. xml and retrieve them using this object.
What is the difference between ServletConfig and ServletContext Mcq?
Difference between ServletContext vs ServletConfig ServletContext has application-wide scope so define outside of servlet tag in web. xml file. getServletContext() method is used to get the context object.
What is ServletConfig?
ServletConfig is an object containing some initial parameters or configuration information created by Servlet Container and passed to the servlet during initialization. ServletConfig is for a particular servlet, which means one should store servlet-specific information in web.
What is ServletContext in JSP?
ServletContext. It is basically used for getting initialization parameters and for sharing the attributes & their values across the entire JSP application, which means any attribute set by application implicit object would be available to all the JSP pages. Methods: Object getAttribute(String attributeName)
What is the difference between generic servlet and HTTP servlet?
-> GenericServlet is a super class of HttpServlet class. -> The main difference is that, HttpServlet is a protocol dependent whereas GenericServlet is protocol independent. So GenericServlet can handle all types of protocols, but HttpServlet handle only HTTP specific protocols.
What is difference between doGet and doPost?
doGet() shall be used when small amount of data and insensitive data like a query has to be sent as a request. doPost() shall be used when comparatively large amount of sensitive data has to be sent. Examples are sending data after filling up a form or sending login id and password.
What is difference between PrintWriter and ServletOutputStream?
PrintWriter is a character-stream class where as ServletOutputStream is a byte-stream class. The PrintWriter class can be used to write only character-based information whereas ServletOutputStream class can be used to write primitive values as well as character-based information.
What is the difference between servlets and applets?
Applets are executed on client-side i.e applet runs within a Web browser on the client machine. Servlets on other hand executed on the server-side i.e servlet runs on the web Page on server. Important methods of applet includes init(), stop(), paint(), start(), destroy().
Why do we use ServletConfig?
ServletConfig object is created by web container for each servlet to pass information to a servlet during initialization. This object can be used to get configuration information from web. xml file. when to use : If you want to share information to all sevlet, it a better way to make it available for all servlet.
What does ServletConfig interface do?
Servlet Container creates ServletConfig object for each Servlet during initialization, to pass information to the Servlet. This object can be used to get configuration information such as parameter name and values from deployment descriptor file(web. xml).
How can I get ServletContext and ServletConfig object in a spring bean?
There are two ways to get Container specific objects in the spring bean:Implementing Spring *Aware interfaces, for these ServletContextAware and ServletConfigAware interfaces. ... Using @Autowired annotation with bean variable of type ServletContext and ServletConfig .
2. ServletConfig methods
String getServletName (): Get servlet name defined in web.xml, in above picture, the servlet name is ServletConfigExample.
3. Example for ServletConfig
Below java servlet example will get the servlet name and all init parameters and print them on the page.
4. ServletContext
ServletContext instance is created by a web container when you deploy a web application in it.