RE: getServletContext() throws null pointer
Constructor is the answer to your problem. There are no guarantee that the servlet that set the data will be loaded before the servlet that accessing it. Danny Trieu Internet Business Group Downey Savings and Loan Association, F.A. [EMAIL PROTECTED] (949) 509-4564 The beginning of knowledge is the discovery of something we do not understand. - Frank Herbert (1920-1986) The essence of knowledge is, having it, to apply it; not having it, to confess your ignorance. - Confucius (551-479 BC) -Original Message- From: Oliver Meyn [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 9:08 AM To: [EMAIL PROTECTED] Subject: getServletContext() throws null pointer Hi, I've put an object into the ServletContext with an init servlet started on load via web.xml. Accessing it with my main Action works fine, but when I try to use another servlet (extend HttpServlet) to getServletContext() it throws a null pointer exception (doesn't just return null - goes straight to the exception). From the javadoc on ServletContext I'm led to believe that all servlets in the app share the same ServletContext, so I'm confused. I'm attempting this lookup in the constructor of the servlet - does it have to happen in a doGet or such? Any ideas? Also, is there some way of accessing the ServletContext without being a Servlet? Thanks very much, Oliver - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This message and any attachments are for the intended recipient(s) only and may contain privileged, confidential and/or proprietary information about Downey Savings or its customers, which Downey Savings does not intend to disclose to the public. If you received this message by mistake, please notify the sender by reply e-mail and delete the message and attachments. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: getServletContext() throws null pointer
On Wed, 2003-12-10 at 12:12, Trieu, Danny wrote: Constructor is the answer to your problem. There are no guarantee that the servlet that set the data will be loaded before the servlet that accessing it. I'm attempting to make that guarantee but I can see how the servlets might not care. Further testing reveals that the contructor is not the problem, though, since putting the lookup in a separate function called after construction also fails. Other thoughts? Thanks, Oliver - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getServletContext() throws null pointer
Oliver, Are you overriding init(ServletConfig config) in your init servlet? If so, did you call super.init(config) before you tried accessing the ServletContext? -Richard --- Oliver Meyn [EMAIL PROTECTED] wrote: Hi, I've put an object into the ServletContext with an init servlet started on load via web.xml. Accessing it with my main Action works fine, but when I try to use another servlet (extend HttpServlet) to getServletContext() it throws a null pointer exception (doesn't just return null - goes straight to the exception). From the javadoc on ServletContext I'm led to believe that all servlets in the app share the same ServletContext, so I'm confused. I'm attempting this lookup in the constructor of the servlet - does it have to happen in a doGet or such? Any ideas? Also, is there some way of accessing the ServletContext without being a Servlet? Thanks very much, Oliver - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getServletContext() throws null pointer
On Wed, 2003-12-10 at 12:18, Richard Yee wrote: Oliver, Are you overriding init(ServletConfig config) in your init servlet? If so, did you call super.init(config) before you tried accessing the ServletContext? I'm not overriding init(config) but I am overriding init(). I hadn't been calling super.init() but gave that a shot and no change. I am able to access the ServletContext (and the init-ed object) from both my controlling Action and from a jsp - just not from another servlet. I must be missing something simple yet fundamental... Thanks, Oliver - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getServletContext() throws null pointer
as i understand it, in order to retrieve the servlet context, you need to use the ServletConfig to retrieve it like so: config.getServletContext() this sounds similar to a problem that i had where i was trying to log something from a servlet, just used the log() method and it through an exception pretty much like the one you are experiencing. however, by putting config.getServletContext().log() it threw no exceptions... - Original Message - From: Oliver Meyn [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 5:41 PM Subject: Re: getServletContext() throws null pointer On Wed, 2003-12-10 at 12:18, Richard Yee wrote: Oliver, Are you overriding init(ServletConfig config) in your init servlet? If so, did you call super.init(config) before you tried accessing the ServletContext? I'm not overriding init(config) but I am overriding init(). I hadn't been calling super.init() but gave that a shot and no change. I am able to access the ServletContext (and the init-ed object) from both my controlling Action and from a jsp - just not from another servlet. I must be missing something simple yet fundamental... Thanks, Oliver - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getServletContext() throws null pointer
Oliver, In the last email I sent, I should have asked if you overrode the init(ServletConfig) method in the servlet that is having the null pointer exception, not your init servlet. -Richard --- Oliver Meyn [EMAIL PROTECTED] wrote: Hi, I've put an object into the ServletContext with an init servlet started on load via web.xml. Accessing it with my main Action works fine, but when I try to use another servlet (extend HttpServlet) to getServletContext() it throws a null pointer exception (doesn't just return null - goes straight to the exception). From the javadoc on ServletContext I'm led to believe that all servlets in the app share the same ServletContext, so I'm confused. I'm attempting this lookup in the constructor of the servlet - does it have to happen in a doGet or such? Any ideas? Also, is there some way of accessing the ServletContext without being a Servlet? Thanks very much, Oliver - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getServletContext() throws null pointer
On Wed, 2003-12-10 at 12:50, Claire Wall wrote: as i understand it, in order to retrieve the servlet context, you need to use the ServletConfig to retrieve it like so: config.getServletContext() this sounds similar to a problem that i had where i was trying to log something from a servlet, just used the log() method and it through an exception pretty much like the one you are experiencing. however, by putting config.getServletContext().log() it threw no exceptions... Hmm. It appears that the ServletConfig is only accessible to the init() of a given servlet. Within the init() I can getServletConfig() and it appears not to be null, and I can getServletConfig.getServletContext() but that IS null. So no exception but a null context that leaves me in about the same boat. Calling getServletContext() directly within the init() also gives me null. This happens with and without a call to super.init(). This can't be that hard. Is there some extra step to tying an arbitrary servlet to a webapp context apart from calling it from within that context (eg Action within context calls the new servlet)? Thanks, Oliver - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getServletContext() throws null pointer
On Wed, 2003-12-10 at 12:55, Richard Yee wrote: Oliver, In the last email I sent, I should have asked if you overrode the init(ServletConfig) method in the servlet that is having the null pointer exception, not your init servlet. Oh I see - sorry but before testing Claire's hypothesis I hadn't touched the init() methods. Thanks, Oliver - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]