Deactivate Jetty's default 404 error handler

后端 未结 2 737
北海茫月
北海茫月 2021-01-05 01:00

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, out of the box, provi

相关标签:
2条回答
  • 2021-01-05 01:26

    Here's how to define custom error pages -

    http://wiki.eclipse.org/Jetty/Howto/Custom_Error_Pages

    0 讨论(0)
  • 2021-01-05 01:32

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

    If a user doesn't explicitly specify some ErrorHandler, the Jetty server instance seems to register a default 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. 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:

    file 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>
    
    0 讨论(0)
提交回复
热议问题