File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes ServletContext InitParameter Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "ServletContext InitParameter Problem " Watch "ServletContext InitParameter Problem " New topic

ServletContext InitParameter Problem

Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
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...

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

Joined: Aug 25, 2005
Posts: 6
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.
using the above class generate the config object ,you can
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

All the answers to your questions can be found in the API:

If you would like an example app that uses context init params I have one on
There is also one for servlet init-params.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: ServletContext InitParameter Problem
jQuery in Action, 3rd edition