Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContext InitParameter Problem

 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
Can you tell me what is the use of context.getInitParameter() or context.getInitParameterNames() . where we should define init parameters for Context. (Referring to text in bold context is of type ServletContext.)
What is the difference between context.getAttribute() or context.getAttributeNames() & getInitparameter() & getInitParameterNames()?
when i am using the following code on Tomcat 5.0 it shows the outputas given below:






//====================================================================
OUTPUT in web browser
//====================================================================
Printing context-param elements from web.xml...

DB_Driver : sun.jdbc.odbc.JdbcOdbcDriver
DB_UserName : scott
DB_URL : jdbc dbc:MyDataSource
DB_Password : tiger
Printing after manipulating the Context Prameters...

Company Name : SEED INFOTECH PVT. LTD. PUNE
Login Name : Seed
Password : null
//=========================================================================

It is not showing me any initparameter in the output can you help me to understand hoe init parametres can be specified & what would be its use?



Thanx in Advance
Shrinivas Mujumdar

[Code tags fixed]
[ August 27, 2005: Message edited by: David O'Meara ]
 
te zhang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want to get the InitParameter
since the initparameters are configued in the configuration file.
the web.xml, so the config object must be getten.
javax.servlet.ServletConfig
using the above class generate the config object ,you can
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the answers to your questions can be found in the API:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html

If you would like an example app that uses context init params I have one on
http://simple.souther.us.
There is also one for servlet init-params.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic