Link to home
Start Free TrialLog in
Avatar of matthew016
matthew016Flag for Belgium

asked on

init ServerConfig - ServerContext

What's the difference between :
1)
      public void init(){
            ServletConfig config=getServletConfig();
            urlErreur=config.getInitParameter("urlErreur");
            urlIndex=config.getInitParameter("urlIndex");
2)
      public void init(){
            ServletContext c=getServletContext();
            urlErreur=c.getInitParameter("urlErreur");
            urlIndex=c.getInitParameter("urlIndex");
Avatar of rrz
rrz
Flag of United States of America image

>ServletConfig config=getServletConfig();
  urlErreur=config.getInitParameter("urlErreur");  
This refers to a parameter for a servlet.  In context's web.xml  file entries look like  
<servlet>
 .
 .
<init-param>
   <param-name>urlErreur</para-name>
   <param-value>someValue</para-value>
</init-param>
</servlet>

>ServletContext c=getServletContext();
  urlErreur=c.getInitParameter("urlErreur");
This refers to a context wide parameter. Its entry into the web.xml file looks like
<web-app ....>
.
.
.
<context-param>
   <param-name>urlErreur</para-name>
   <param-value>someValue</para-value>
</context-param>
</web-app>

   
SOLUTION
Avatar of vikrant4u2
vikrant4u2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of matthew016

ASKER


So if I want to retrieve information that is specific to a servlet I use : ServletConfig

and to retrieve information that are shared for more servlets : ServletContext

or I didn't understand ?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial