• 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

How to access init parameter from web.xml in servlet

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
berender mavi
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still getting the same null.

My code is as follows



and output on console is

 
Victor M. Pereira
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"));

}
reply
    Bookmark Topic Watch Topic
  • New Topic