jump to navigation

ServletConfig vs ServletContext August 23, 2005

Posted by Coolguy in Servlets/Jsp.
trackback

ServletConfig :

  • One ServletConfig per servlet
  • Used to pass deploy-time info to servlet and configured in deployment descriptor
  • Used to access ServletContext
  • Within servlet element in DD:

    <servlet>
    <display-name>InitParamTest</display-name>
    <servlet-name>InitParamTest</servlet-name>
    <servlet-class>
    test.InitParamTest</servlet-class>
    <init-param>
    <description>test parameter</description>
    <param-name>myname</param-name>
    <param-value>DummyValue</param-value>
    </init-param>
    </servlet>

  • getServletConfig.getInitParameter(“myname”);
  • Available to only to the servlet which has init-param configured

ServletContext:

  • One per webapp
  • If webapp is distributed, one per JVM
  • Used to access webapp parameters configured in deployment descriptor
  • Application bulletin-board
  • Use to get server info
  • Within web-app element of DD
  • <context-param>
    <param-name>myname</param-name>
    <param-value>DummyValue</param-value>
    </context-param
    getServletContext.getInitParameter(“myname”);

  • Avilable to any servlet or JSP that are part of webapp
About these ads

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: