• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can servletconfig be null?  RSS feed

 
Iris Hoekstra
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a servlet that looks like this:



When it gets to line a, it throws a NullPointerException. While debugging, I can see that the servletconfig object is null so that is while getServletContext() fails.

For lack of a better idea I added


and later


As I feared, this didn't make any difference.

In the web.xml, the servlet is declared like this:


and then further down like this:


I tried turning these around; made no difference.

Any ideas?

[ August 23, 2005: Message edited by: Iris Hoekstra ]
[ August 23, 2005: Message edited by: Iris Hoekstra ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly this isn't going to work, you're trying to mix in ServletContextAttributeListener responsibility to a HttpServlet, which may not be advisable but is otherwise fine, but then you're trying to get to respond to Listener events as a Servlet, and this just isn't going to happen.

Servlets require a request/response architecture, the client sends a request and receives a response. In your case you're trying to send a response without an initiating request. Even if we get it fixed, it doesn't mean anything

Dave
 
Iris Hoekstra
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sigh - I see. Guess I'll have to refactor a few things. What I'm trying to do is this:

I have a servlet that starts a thread, then forwards to a jsp that says something like "the process has started" to the user. Then when the thread finishes the servlet (the same one that started the thread) adds an attribute to the servletcontext. As soon as this happens I somehow need to go to another servlet to do more stuff.

Try as I might, I cannot find a neat and tidy way to do this. Or any way at all. Any suggestions will be much appreciated...
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest way I've seen is to use a hidden form. The user submits the data, you return immediately with a page saying "Please wait", but there is also a hidden form that gets auto-submitted by some attached Javascript. It is this form that does the real work, and the client has a nice 'please wait' message until it finishes.

I've seen some monstrous solutions to this problem, but personally I don't think you need to go too far.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!