How to use application object in Servlet init method

Application object can be used in servlet init method by using ServletContext object. Application object is property of JSP, we have to use ServletContext. This will work same with application scope to application context. This object is available globally to whole application.

Init method of servlet passes parameter of ServletConfig. This ServletConfig object uses getServletConfig method.

public void init() throws ServletException
{
      ServletConfig config = getServletConfig();
      ServletContext sc = config.getServletContext();
}
Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post