Forums Register Login

How can servletconfig be null?

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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...
+Pie Number of slices to send: Send
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.
Evacuate the building! Here, take this tiny ad with you:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2561 times.
Similar Threads
doubt with filters
ServletContext AttributeListener
init(ServletConfig config) query
My example with ServletContextListener and ServletContextAttrib.
getServletConfig() does not work
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:27:18.