| Author |
How to access init parameter from web.xml in servlet
|
berender mavi
Greenhorn
Joined: Feb 18, 2011
Posts: 29
|
|
Hi All,
I am using a init param named as Name in servlet parameter.But when i am running follwing code in doGet
getting null.why ? can you please tell me?
my web.xml is as follows:
one more thing when i am overriding the init() method and using the same code in it.
why am getting 2 times printing for one statement in init().First time i am getting the correct result from web.xml but in second printing it's again null.
Please help.Thanks
|
 |
Victor M. Pereira
Ranch Hand
Joined: Mar 02, 2012
Posts: 50
|
|
If your using the same code in the init, why override it?
The init method sets the servletConfig, you should check if your servletConfig has what is supposed to have.
When you make changes in the DD, you should try to redeploy it. Some servers don't have the automatic hot redeploy.
Try stopping the server, wait 30 seconds and start it again.
|
regards,
Victor M. Pereira
|
 |
berender mavi
Greenhorn
Joined: Feb 18, 2011
Posts: 29
|
|
Still getting the same null.
My code is as follows
and output on console is
|
 |
Victor M. Pereira
Ranch Hand
Joined: Mar 02, 2012
Posts: 50
|
|
|
May sound dumb, but could you try deleting <load-on-startup>1</load-on-startup> line from your DD. Is a running theory bu tjust try it.
|
 |
Bharat Kasodariya
Ranch Hand
Joined: Aug 19, 2011
Posts: 36
|
|
I think you should override
public void init(ServletConfig config) method to get config param.
The code will be like
public void init(ServletConfig config){
// Store the ServletConfig object and log the initialization
super.init(config);
System.out.println("Name is"+config.getInitParameter("Name"));
}
|
 |
 |
|
|
subject: How to access init parameter from web.xml in servlet
|
|
|