简体   繁体   English

FlexContext.getServletContext()返回NPE

[英]FlexContext.getServletContext() is returning NPE

I'm having an issue with Flex. 我在Flex上遇到问题。

The following java line is throwing NPE. 以下Java行抛出NPE。

ServletContext servletContext = FlexContext.getServletContext();

However, the following command works just fine and throws no exception. 但是,以下命令可以正常工作,并且不会引发异常。 After the command executes, httpServletRequest is null (as expected). 命令执行后,httpServletRequest为空(如预期)。

HttpServletRequest httpServletRequest = FlexContext.getHttpRequest();

I was able to find the answer. 我找到了答案。 I think that Flex pulled an abstraction on us. 我认为Flex对我们进行了抽象。 I think that getServletContext() actually calls FlexContext.getServletConfig() within the method. 我认为getServletContext()实际上在方法中调用FlexContext.getServletConfig()。 Because of this internal call, when Flex then internally calls getServletContext (), the method throws NPE. 由于此内部调用,因此当Flex然后内部调用getServletContext()时,该方法将引发NPE。

I simply altered the code to the following. 我只是将代码更改为以下内容。

ServletConfig servletConfig = FlexContext.getServletConfig();
if (servletConfig != null) {
    ServletContext servletContext = servletConfig.getServletContext();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 getServletContext()。getAttribute()返回null吗? - getServletContext().getAttribute() returning null? getServletConfig()/ getServletContext()返回null值 - getServletConfig() / getServletContext() returning null value getServletContext()。getRealPath(“”)返回null在WebLogic中 - getServletContext().getRealPath(“”) returning null In WebLogic getServletContext()。getRealPath()在控制器(NPE)中不起作用,但在jsp中工作 - getServletContext().getRealPath() doesn't work in controller (NPE), but works in jsp 使用 getServletConfig().getServletContext().getAttribute() (Java) 时获取 NPE - Getting NPE when using getServletConfig().getServletContext().getAttribute() (Java) GetServletContext在扩展HttpServlet的类中返回null - GetServletContext returning null in a class that extends HttpServlet request.getServletContext().getRealPath(); 正在返回我的目标目录而不是 src? - request.getServletContext().getRealPath(); is returning my target directory instead of src? MySQL返回NPE从表中获取ID(作为字符串) - MySQL returning NPE getting an ID from a table (as a string) ServletRequest.getServletContext()的UnsupportedOperationException - UnsupportedOperationException for ServletRequest.getServletContext() req.getsession()。getservletcontext()和getservletcontext()之间的区别 - difference between req.getsession().getservletcontext() and getservletcontext()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM