ServletContext何时返回null

ServletContext何时返回null

本文介绍了ServletContext何时返回null RequestDispatcher?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说:

For ServletContext无法返回RequestDispatcher的原因是什么?起初我认为如果传递了无效路径但是没有返回null,则会在浏览器上产生404.

For what reason would the ServletContext not be able to return a RequestDispatcher? At first I figured it would be if an invalid path was passed but that doesn't return null, it results in a 404 on the browser.

我正在检查null在调用forward()方法之前,在日志中我可以看到,曾经有一段时间RequestDispatcher为null,但我不知道为什么,我无法找到如何复制它。

I am checking for null before calling the forward() method and in the logs I can see that once in awhile the RequestDispatcher is null but I don't know why and I can't find out how to duplicate it.

谢谢

更新

像Fazal建议我试过为'http://www.google.com/'创建了一个RequestDispatcher,看看会发生什么。这导致了IllegalArgumentException

Like Fazal suggested I tried created a RequestDispatcher to 'http://www.google.com/' to see what would happen. This caused an IllegalArgumentException

Exception在我的try / catch块中被捕获,因此我没有机会检查RequestDispatcher是否为null或调用forward()方法。

The Exception was caught in my try/catch block so I never got the chance to check if the RequestDispatcher was null or call the forward() method.

因此,ServletContext#getRequestDispatcher()方法必须有另一种方法返回null而不抛出异常?

So there must be another way for the ServletContext#getRequestDispatcher() method to return null without throwing an Exception?

推荐答案

Tomcat为当前上下文之外的路径返回 null ,例如 /../ foo (但Jetty没有,因此它是特定于实现的。)

Tomcat returns null for path outside of the current context, such as /../foo (but Jetty doesn't, so it's implementation-specific).

这篇关于ServletContext何时返回null RequestDispatcher?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:43