Blog

What is the difference between ServletConfig & ServletContext?

What is the difference between ServletConfig & 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 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 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.

What is diff between JSP and servlet?

Difference between Servlet and JSP

Servlet JSP
Servlets are faster as compared to JSP, as they have a short response time. JSP is slower than Servlets, as the first step in the JSP lifecycle is the conversion of JSP to Java code and then the compilation of the code.
Servlets are Java-based codes. JSP are HTML-based codes.

How can I get ServletContext and ServletConfig objects in a spring bean?

There are two ways to get Container specific objects in the spring bean:

  1. Implementing Spring *Aware interfaces, for these ServletContextAware and ServletConfigAware interfaces.
  2. Using @Autowired annotation with bean variable of type ServletContext and ServletConfig .

How many ServletContext is created for an application?

one ServletContext object
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.

How many ServletContext objects are available for?

Which of the following methods are included in the ServletConfig interface?

Methods of ServletConfig interface public String getInitParameter(String name):Returns the parameter value for the specified parameter name. public Enumeration getInitParameterNames():Returns an enumeration of all the initialization parameter names. public String getServletName():Returns the name of the servlet.

Which is better servlet or JSP?

Servlet is faster than JSP. JSP is slower than Servlet because the first step in JSP lifecycle is the translation of JSP to java code and then compile. Servlet can accept all protocol requests. In Servlet we have to implement everything like business logic and presentation logic in just one servlet file.

What is the difference between HTML and JSP?

JSP is a technology which is used to create dynamic web applications. HTML is a standard markup language which is used to create the structure of web pages. JSP allow to place the custom tag or third party tag. It does not allow to place the custom tag or third party tag.

How can I get Getervletcontext?

Example of getServletContext() method

  1. //We can get the ServletContext object from ServletConfig object.
  2. ServletContext application=getServletConfig().getServletContext();
  3. //Another convenient way to get the ServletContext object.
  4. ServletContext application=getServletContext();

What is the use of context loader listener in spring?

ContextLoaderListner is a Servlet listener that loads all the different configuration files (service layer configuration, persistence layer configuration etc) into single spring application context. This helps to split spring configurations across multiple XML files.

Share this post