Solved

init ServerConfig - ServerContext

Posted on 2006-07-14
4
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

There is a lot to be said for protecting yourself and your accounts with 2 factor authentication.  I found to my own chagrin, that there is a big downside as well.
This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 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