yes actually i did, sorry i forgot.
here's where i create the object
public class LCMS3 implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
log.info("Starting LCMS3 daemon");
ServletContext sc = sce.getServletContext();
LiveInfo li = new LiveInfo();
li.setTest("lerolero");
sc.setAttribute("live", li);
....
and im able to see it, i have a servlet that is able to access the live
attribute and get the info without any problem.
public class testcontext extends HttpServlet {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
ServletContext sc = getServletContext();
LiveInfo li = (LiveInfo) sc.getAttribute("live");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet testcontext</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet testcontext at " + request.getContextPath
() + "</h1>");
out.println("<p>test: "+li.getTest()+"</p>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
On Jan 31, 2011, at 4:40 PM, Caldarale, Charles R wrote:
>> From: alexis [mailto:[email protected]]
>> Subject: Re: custom class as resource
>
>> LiveInfo li = (LiveInfo) sc.getAttribute("live");
>
>> why im getting a null pointer on the sc.getAttribute line?
>
> Because you never created an attribute named "live" in the ServletContext.
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you received
> this in error, please contact the sender and delete the e-mail and its
> attachments from all computers.
>
>
> ---------------------------------------------------------------------
> 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]