空页面而不是自定义 tomcat 错误页面

发布于 2024-09-26 11:54:28 字数 960 浏览 5 评论 0原文

我的设置: Apache 2.2 + Tomcat 6.0 @ Windows 2008 R2 64bit

  • 静态网页: /
  • servlet: /foo
  • tomcat 和 apache 通过 mod_jk 连接
  • 404.jsp 放在 tomcat\webapps\ROOT

tomcat\conf\web.xml 中:

<error-page>
 <error-code>404</error-code>
 <location>/404.jsp</location>
</error-page>

apache\conf\extra\httpd-ssl.conf:

JkMount /foo/* worker1
JkMount /404.jsp worker1

当我打开 https://...../404.jsp 显示我的自定义错误页面。 但是当我打开 https://...../foo/nonexisting.html将显示一个空白页面。

如果我从 web.xml 中删除 ... 代码并打开 https://...../foo/nonexisting.html 然后显示tomcats自己的404。

有什么提示吗?

My setting: Apache 2.2 + Tomcat 6.0 @ Windows 2008 R2 64bit

  • static webpages: /
  • servlet: /foo
  • tomcat and apache are connected by mod_jk
  • 404.jsp is placed in tomcat\webapps\ROOT

tomcat\conf\web.xml:

<error-page>
 <error-code>404</error-code>
 <location>/404.jsp</location>
</error-page>

apache\conf\extra\httpd-ssl.conf:

JkMount /foo/* worker1
JkMount /404.jsp worker1

When I open https://...../404.jsp my custom error page is displayed.
But when I open https://...../foo/nonexisting.html an empty page is displayed.

If I remove the <error-page>...</error-page> code from web.xml and open https://...../foo/nonexisting.html then tomcats own 404 is displayed.

Any hints?

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

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

发布评论

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

评论(7

秉烛思 2024-10-03 11:54:28

Jkmount 应该将上下文作为参数,例如:

JkMount /mycontext/* worker1

然后以这种方式访问​​页面:

https://mycontext/someservlet/

https://mycontext/foo/nonexisting.html 

The Jkmount should have the context as parameter, ex:

JkMount /mycontext/* worker1

then the pages are accessed this way:

https://mycontext/someservlet/

or

https://mycontext/foo/nonexisting.html 
丢了幸福的猪 2024-10-03 11:54:28

据我所知,Web应用程序的错误无法通过放置在ROOT中的错误页面来处理。我现在将 404.jsp 放入每个 Web 应用程序中(/foo/404.jsp、/bar/404.jsp,...),现在它可以工作了。我可以安全地删除 ROOT 中的 404.jsp,但是如果我删除 /foo 或 /bar 中的 404.jsp,则当任一 Web 应用程序中发生 404 时,都会提供一个空白页面。 tomcat 会忽略“location”元素中的前导 /,或者该元素的内容会附加到“调用”web 应用程序的路径中。

As far as i can see it, webapps' errors can't be handled with error pages placed in ROOT. I now put the 404.jsp in every webapp (/foo/404.jsp, /bar/404.jsp, ...) and now it works. I can safely delete the 404.jsp in ROOT, but if I delete the 404.jsp in /foo or /bar a blank page is served if a 404 occurres in either webapp. Either tomcat ignores the leading / in the "location" element or the content of this element is appended at the 'calling' webapp's path.

梦巷 2024-10-03 11:54:28

注意:您需要确保指定的页面不以数字开头(即:404.jsp)。这是因为,根据 Java 语法,类名不能以数字开头。

http://www.jguru.com/faq/view.jsp?EID=492774

希望有帮助:-)

Note: You need to be sure that the page you specify does not begin with a number (i.e.: 404.jsp). This because, according to Java Syntax, you cannot start a class name with a number.

http://www.jguru.com/faq/view.jsp?EID=492774

Hope that helps :-)

快乐很简单 2024-10-03 11:54:28

如果加载 404.jsp 时工作正常,并且当 tomcat 实际尝试使用该页面处理 404 错误时显示空白页面,则可能意味着 404.jsp 的源代码中存在错误,该错误仅通过使用 errorData 触发目的。

检查日志。我遇到了类似的空白页问题,结果发现我有一个 标签库 URL 不正确

编辑

此外,JkMount 应该不是必需的,因为 tomcat 已经生成了这些 404(即它们不在 Apache 的权限范围内)。

If it works fine when loading 404.jsp, and shows a blank page when tomcat actually tries to use the page to handle a 404 error, it could mean that there is an error in 404.jsp's source code that's only triggered by using the errorData object.

Check the logs. I was having a similar blank page problem and it turned out that I had an incorrect taglib URL.

EDIT

Also, JkMount should not be necessary since tomcat is already generating these 404s (i.e. they are not in Apache's purview).

再可℃爱ぅ一点好了 2024-10-03 11:54:28

我也遇到了这个问题,事实证明罪魁祸首是我在错误页面位置输入了应用程序上下文根的名称。也就是说,

<error-page>
 <error-code>404</error-code>
 <location>/MyApp/404.jsp</location>
</error-page>

虽然它当然应该是

<error-page>
 <error-code>404</error-code>
 <location>/404.jsp</location>
</error-page>

I had this problem as well, and it turns out the culprit was that I'd typed the name of the application context root into the error page location. That is,

<error-page>
 <error-code>404</error-code>
 <location>/MyApp/404.jsp</location>
</error-page>

Whereas it should of course have been

<error-page>
 <error-code>404</error-code>
 <location>/404.jsp</location>
</error-page>
执手闯天涯 2024-10-03 11:54:28

我在运行静态 Web 项目时遇到了这个问题。我已经完成了以下实现,它对我有用。

在 %CATALINA_HOME%/conf/web.xml 中添加了以下行

    <error-page> 
    <error-code>404</error-code>
    <location>/error_404.html</location>
    </error-page>

I have faced this issue while running a static web project.I have done the following implementation, and it has worked for me.

Added the following lines in %CATALINA_HOME%/conf/web.xml

    <error-page> 
    <error-code>404</error-code>
    <location>/error_404.html</location>
    </error-page>
走走停停 2024-10-03 11:54:28

它准确地显示 404 页面未找到,否则?
因为其他一些错误代码也可用,例如 400,401,403,500。
看看这个链接
http://docs.yahoo.com/docs/writeus/error.html

如果您有任何其他错误代码,请在 web.xml 文件中添加。
希望这有帮助。
快乐编码...

Its shows exactly 404 page not found or else?
Because some other error codes also avail like 400,401,403,500.
Have a look at this link for this
http://docs.yahoo.com/docs/writeus/error.html

If you have any other add that error codes aslo in web.xml file.
Hopes this helps.
Happy coding...

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