Solved

init ServerConfig - ServerContext

Posted on 2006-07-14
4
369 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
getting Http 404 error in jsp forms 8 85
servlet concurrency 13 118
servlet example 17 59
iterator/ListIterator approach 17 54
Read  the original post  on Monitis Blog. Hi.  My name is Erik Dietrich, and this is the first time I’ve posted on the Monitis blog.  By way of introduction, I thought it would make sense to talk about my initial experience with Monitis.   Befo…
This article was originally published on Monitis Blog, you can check it  here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sour…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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