Solved

init ServerConfig - ServerContext

Posted on 2006-07-14
4
359 Views
Last Modified: 2010-04-01
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");
0
Comment
Question by:matthew016
  • 2
4 Comments
 
LVL 27

Expert Comment

by:rrz
ID: 17112728
>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>

   
0
 
LVL 2

Assisted Solution

by:vikrant4u2
vikrant4u2 earned 100 total points
ID: 17113469
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.The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized

ServletConfig: The object created after a servlet is instantiated and its default constructor is read. It is created to pass initialization information to the servlet.
0
 
LVL 9

Author Comment

by:matthew016
ID: 17114100

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 ?
0
 
LVL 27

Accepted Solution

by:
rrz earned 400 total points
ID: 17114345
I would  say,
If you want to make information available to a specific servlet then use a <init-param>  tag and and access it through  ServletConfig.
If you want to make information available to all servlets and JSPs in the web app then use a <context-param> tag and access it through ServletContext.  
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now