• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Context usage through WAR file

 
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I think most of you have gone through the sample applications in WS4.
In the YourCo sample, they use Hitcount bean to keep track of the number of hits to the particular page.
In the bean code, the JSP takes the servletContext to pull the parameter values of the database. i.e userId, Password and so on.
These values are kept in the deployment descriptor file of this Web application. i.e. in web.xml file.
I want to know how does my servletcontext gets thse values when I use the following statement in my JSP :
ServletConfig sConfig = getServletConfig();
String userID = WebSphereSamples.Configuration.Config.getUserID(sConfig);
Also please explain me how this works.
Thanks.


------------------
L Goundalkar
lggoundalkar@hotmail.com
Sun Certified Programmer for Java 2 Platform
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it's pretty simple, and ALL explained in the Servlet 2.2 specification from Sun.
Section 4.2 says:
"4.2 Initialization Parameters
A set of context initialization parameters can be associated with a web application and are made available by the following methods of the ServletContext interface:
� getInitParameter()
� getInitParameterNames()
Initialization parameters can be used by an application developer to convey setup information, such as a webmaster�s e-mail address or the name of a system that holds critical data."
Later in the "Examples" section of web.xml files (Section 13.3) they show how you set this up in a web.xml file:
"< web-app>
< display-name>A Simple Application< /display-name>
< context-param>
< param-name>Webmaster< /param-name>
< param-value>webmaster@mycorp.com< /param-value>
< /context-param>
...
< /web-app>"
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
[This message has been edited by Kyle Brown (edited November 21, 2001).]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic