Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting Servletcontext in a class

 
Elizabath Lima
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I would like to get an attribute in WebApplicationContext in DWRFacade class. I extented HttpServlet to DWRFacade class. But i'm getting

WARNING: Method execution failed:
java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:159)
at com.scs.rb.web.utils.DWRFacade.getCounties(DWRFacade.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

I'm sure abt the values in the servletCOntext.

Hw i'll get the values from the servletContext..

Thanks in advance
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your servlet initialised?
 
struts lover
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your code. So that, we can have idea about the problem.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"struts lover",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Elizabath Lima
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I'm pasting my code for the class


[Edit by Dave - code tags added]
[ April 07, 2006: Message edited by: David O'Meara ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Peter may be right, it looks like your servlet has not been initialised. You could try setting it to initialise on startup in your web.xml, that may help things.
 
Elizabath Lima
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

Thanks for your reply.
I'm developing this appication in Spring and I'm loading all the necessary xmls using ContextLoaderListener. And the DWRFacade class's bean is defined in one of the xml too.

By the time i tried extending the RBDispatcherServlet to the DWRFacade class, but that too doesn't work.

Can you please tell me what is wrong in my deeds?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic