Solved

init ServerConfig - ServerContext

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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 79
excpetion with multiple catch 11 116
withoutString  challenge 40 198
eclipse buid path vs tomcat lib path 10 23
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Knowing where your website is hosted is as important as the features you receive, the monthly fee, and the support you receive. Due diligence should be done when choosing your next hosting provider.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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