tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexis <alz...@gmail.com>
Subject Re: custom class as resource
Date Mon, 31 Jan 2011 19:28:02 GMT
package com.lesi.lcms3.core;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

public class NewClass extends HttpServlet {

    private ServletContext sc;

    public String aVer()
    {
    LiveInfo li = (LiveInfo) sc.getAttribute("live");

    return li.getTest();
    }

    @Override
    public void init(ServletConfig config) throws ServletException
    {
    super.init(config);
    sc = config.getServletContext();
    }

}


why im getting a null pointer on the sc.getAttribute line?




On Jan 31, 2011, at 7:36 AM, Konstantin Kolinko wrote:

> 2011/1/31 alexis <alzrck@gmail.com>:
>> actually im already using a class extending servletcontextlistener, this class is
the responsible to start all other threads on processing. Some threads stores results on a
DB, some threads should store results in an object to be accesed by a servlet and presented
via web.
>> 
>> If i use the a) approach and i use it as Listener, how can i access this class from
other threads/classes on my webapp?
> 
> ServletContext#setAttribute(String,Object)
> ServletContext#getAttribute(String)
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message