停用Jetty的默认404错误处理程序 [英] Deactivate Jetty's default 404 error handler

查看:1264
本文介绍了停用Jetty的默认404错误处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Spring 3.1 Web应用程序中提供一个自定义的404错误页面,但是我无法停用Jetty 8的默认404错误页面.

I want to provide a custom 404 error page in my Spring 3.1 web application, but I cannot deactivate Jetty 8's default 404 error page.

Jetty 8开箱即用,提供默认的404错误页面: 当访问Jetty托管的网站并提供任何Servlet无法处理的URL路径时(例如,通过访问http://www.example.com/nonexisting),Jetty会使用自己的默认HTML错误页面

Jetty 8, out of the box, provides a default 404 error page: when visiting a Jetty-hosted website, and providing a URL path that is not handled by any servlet (e.g. by visiting http://www.example.com/nonexisting ), Jetty responses with its own default HTML error page:

HTTP ERROR 404

Problem accessing /nonexisting. Reason:

    Not Found
Powered by Jetty://

要替换此默认行为,

  • I've removed the DefaultHandler from my Jetty XML file,
  • I've edited my web.xml to include both Servlet 2.5 and Servlet 3.0 error handler locations pointing to /error,
  • I've set up a dedicated @Controller for handling the request to /error,

,但是我的网站仍然返回 Jetty自己的默认HTML错误页面.

but my website still returns Jetty's own default HTML error page.

Jetty 8的官方文档讨论了如何设置自定义错误页面" ,但是那里的建议说

  • 配置一个自定义的Jetty错误处理程序(我不想这样做,我想如上所述在我自己的Spring @Controller内部执行此操作)
  • 创建捕获所有上下文并创建映射到/ URI的根" Web应用程序". (我不想这样做,因为在我的web.xml内部,我已经将Spring MVC的DispatcherServlet映射到了/.
  • to configure a custom Jetty error handler (I don't want to do this, I want to do it inside my own Spring @Controller as mentioned above)
  • to create a "catch all context and create a "root" web app mapped to the / URI." (I don't want to do this as inside my web.xml I have already mapped Spring MVC's DispatcherServlet to /.

如何关闭Jetty的默认错误处理程序,并按照上述指示进行错误处理?

How can I turn off Jetty's default error handler and have the error handling be done as pointed out above?

推荐答案

我的问题的解决方案是添加自定义org.eclipse.jetty.server.handler.ErrorHandler.

The solution to my problem was to add a custom org.eclipse.jetty.server.handler.ErrorHandler.

如果用户未明确指定某些ErrorHandler,则Jetty服务器实例似乎注册了默认的ErrorHandler.

If a user doesn't explicitly specify some ErrorHandler, the Jetty server instance seems to register a default ErrorHandler.

http://www.eclipse.org/jetty/documentation/所述current/custom-error-pages.html ,要注册自定义ErrorHandler,您可以按照以下步骤操作.

As outlined on http://www.eclipse.org/jetty/documentation/current/custom-error-pages.html, to register a custom ErrorHandler, you can follow the following steps.

  1. 实现某些org.eclipse.jetty.server.handler.ErrorHandler子类,例如com.example.CustomErrorHandler.
  2. 将此子类提供给您的Eclipse服务器实例,例如通过将CustomErrorHandler捆绑到jar文件中,然后将该jar文件复制到${jetty.base}/lib/ext目录中.
  3. 配置您的Jetty服务器实例以将此自定义ErrorHandler注册为Bean:
  1. Implement some org.eclipse.jetty.server.handler.ErrorHandler subclass, e.g. com.example.CustomErrorHandler.
  2. Make this subclass available to your Eclipse server instance, e.g. by bundling CustomErrorHandler in a jar file and then copying that jar file into the ${jetty.base}/lib/ext directory.
  3. Configure your Jetty server instance to have this custom ErrorHandler registered as a bean:

文件jetty.xml:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">

  <!-- more configuration -->

  <Call name="addBean">
    <Arg>
      <New class="com.example.CustomErrorHandler">
        <Set name="server"><Ref refid="Server" /></Set>
      </New>
    </Arg>
  </Call>
</Configure>

这篇关于停用Jetty的默认404错误处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆