java.lang.NullPointerException Sun PetStore CatalogFacade
在Sun Java PetStore demo index.jsp文件中,我在java.lang.NullPointerException Sun PetStore CatalogFacade,java,eclipse,Java,Eclipse,在Sun Java PetStore demo index.jsp文件中,我在cf CatalogFacade cf = (CatalogFacade)getServletContext().getAttribute("CatalogFacade"); List<Tag> tags=cf.getTagsInChunk(0, 12); <--- cf is Null 我的第一个调查是看getServletContext().getAttribute(“CatalogFacad
cf
CatalogFacade cf = (CatalogFacade)getServletContext().getAttribute("CatalogFacade");
List<Tag> tags=cf.getTagsInChunk(0, 12); <--- cf is Null
我的第一个调查是看
getServletContext().getAttribute(“CatalogFacade”)
返回一个null
如果是,那么您从未在应用程序中存储过CatalogFacade
对象。也许可以考虑使用getServletContext().setAttribute(“CatalogFacade”,cf)存储它代码>
这就是我可以帮助您的(您提供的信息很少)。我的第一个调查将是查看getServletContext().getAttribute(“CatalogFacade”)
返回一个null
如果是,那么您从未在应用程序中存储过CatalogFacade
对象。也许可以考虑使用getServletContext().setAttribute(“CatalogFacade”,cf)存储它代码>
这就是我可以帮助您的(您提供的信息很少)。您的ServletContext
是否有属性“catalogafacade”?如果您询问web.xml中的条目中是否有,则否。您的ServletContext
是否有属性“catalogacade”?如果您询问web.xml中的条目中是否有,那么不,我在哪里调用setAttribute呢?根据这里的答案,我没有上下文,但我不知道如何向上下文添加内容。我在哪里调用setAttribute?根据这里的答案,我没有上下文,但我不知道如何向上下文添加内容。
public void contextInitialized(ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
context.setAttribute("CatalogFacade", this);
}