HttpServletRequest#getRemoteAddr() 返回 NULL

发布于 2024-12-28 06:47:45 字数 237 浏览 0 评论 0原文

为什么 HttpServletRequest.getRemoteAddr() 返回null 有时?对于大约十分之二的相同请求,会无缘无故地返回 null

Why does HttpServletRequest.getRemoteAddr() return null sometimes? For approximately 2 out of 10 identical requests is returns null for no apparent reason.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

当爱已成负担 2025-01-04 06:47:45

使用Tomcat7。显然,如果请求已被使用,即已发送响应,则 getRemoteAddr() 可以返回 NULL。有时它甚至会抛出 NPE。无论如何,我的代码中有一个错误。

Using Tomcat7. Apparently getRemoteAddr() can return NULL if the request has already been consumed, i.e. a response has been sent. It can even throw NPE sometimes. An error in my code in any case.

酒中人 2025-01-04 06:47:45

您是否将请求对象传递给另一个线程以异步读取它?在某些 Web 容器中,一旦 servlet 线程完成,请求对象将被回收/重置。那么当调用 request.getRemoteAddr() 时,您可能会得到 null

Did you pass the request object to another thread to read it asynchronously? In some web container, request objects will be recycled/reset once the servlet thread is finished. Then you might get null when request.getRemoteAddr() is called.

林空鹿饮溪 2025-01-04 06:47:45

这可能是所使用的特定 servlet 容器或代理中的错误或配置错误。查找您正在使用的版本,检查其版本并检查此错误是否已报告给其维护者,并检查是否有可以升级到的新版本。

That would be either a bug or a misconfiguration in the specific servletcontainer or proxy used. Lookup which one you are using, check its version and check if this bug has been reported before to its maintainers and check if there is a newer version to which you can upgrade.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文