This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes getting Servletcontext in a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "getting Servletcontext in a class" Watch "getting Servletcontext in a class" New topic
Author

getting Servletcontext in a class

Elizabath Lima
Ranch Hand

Joined: Nov 23, 2005
Posts: 32
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

Joined: Oct 30, 2001
Posts: 1970
Is your servlet initialised?


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
struts lover
Greenhorn

Joined: Jan 30, 2004
Posts: 1
Post your code. So that, we can have idea about the problem.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Elizabath Lima
Ranch Hand

Joined: Nov 23, 2005
Posts: 32
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Nov 23, 2005
Posts: 32
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting Servletcontext in a class
 
Similar Threads
How does the container set the context/config objects?
struts servlet init
Can a request be forwarded to a resource in different web application and the same web container?
How to get servlet's full path name
ActionForm