• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletConfig doubt??

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I tried the some examples with regards to servlet config and context. When I say out.println(getServletConfig().getInitParameter("adminEmail")); and when I dont set any init params in the web.xml, the line prints null?? How and why this happens instead of giving an error??
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why you think it should give error?
use getServletConfig().getInitParameter("adminEmail").length() and see output
Then try to understand why getServletConfig().getInitParameter("adminEmail")
gives null and why getServletConfig().getInitParameter("adminEmail").length()
gives error.it is just basic java.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gowher,

I know that when you say .length(), it will give you a null pointer exception...My question is, how my servlet knows that when I say out.println(getServletConfig().getInitParameter("adminEmail")); or as a matter of fact out.println(getServletConfig().getInitParameter("Some stupid thing")); when there is no param-name tag in the DD that matches Some stupid thing???
[ January 04, 2007: Message edited by: Jothi Shankar Kumar Sankararaj ]
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "how my servlet knows"? The config parameter doesn't exist, so the call returns null. What do you think should happen instead?
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

So if the parameter does not exist, it prints out null. Does this also applies to context param??I thing I got it.

Thanks ranchers.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this also applies to context param?

This kind of information is generally found in the javadocs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic