Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between ServletConfig and ServletContext

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 280
    Comment on it

    ServletConfig

    ServletConfig is use to initialize a servlet. Its scope is within the servlet i.e.,when servlet starts executing, ServletConfig object will be available until execution of servlet is completed. For a particular servlet, there is only one ServletConfig object. getServletConfig() method is used to get the ServletConfig object.

    Example:

    <servlet>
        <servlet-name>DemoServlet</servlet-name>
        <servlet-class>DemoServlet</servlet-class>
    
        <init-param>
            <param-name>name</param-name>
            <param-value>garry</param-value>
        </init-param>
    </servlet>
    

    ServletContext

    ServletContext helps to communicate between servlet container and all of its servlet. Its scope is within the web application (it is common for all the servlet) i.e., ServletContext object will be available until the execution of web application is completed, and its object will be destroyed once web aaplication remove from server. getServletContext() method is used to get the ServletContext object.

    Example:

    <context-param>
        <param-name>dbdriver</param-name>
        <param-value>com.mysql.jdbc.Driver</param-value>
    </context-param>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: