File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "getting Servletcontext in a class" Watch "getting Servletcontext in a class" New topic

getting Servletcontext in a class

Elizabath Lima
Ranch Hand

Joined: Nov 23, 2005
Posts: 32

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:
at javax.servlet.GenericServlet.getServletContext(
at com.scs.rb.web.utils.DWRFacade.getCounties(
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

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

Joined: Jan 10, 2002
Posts: 63870

"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.

JavaRanch Sheriff

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

Joined: Nov 23, 2005
Posts: 32

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

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:
subject: getting Servletcontext in a class
It's not a secret anymore!