我将错误处理程序设置为jetty时遇到了一些问题:

我创建自己的错误处理程序:

public class ServerErrorPageErrorHandler extends ErrorPageErrorHandler {
@Override
protected void writeErrorPageBody(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks)
        throws IOException
{
    String uri= request.getRequestURI();

    writeErrorPageMessage(request,writer,code,message,uri);
    if (showStacks)
        writeErrorPageStacks(request,writer);
    writer.write("<hr><i><small>Powered by OWN-SERVER://</small></i><hr/>\n");
}

}

并将其设置在文件'jett-web.xml'中,该文件位于'/ webapp / WEB-INF /'文件夹中

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>

<Set name="errorHandler">
    <New class="com.mobile.service.handlers.ServerErrorPageErrorHandler"/>
</Set></Configure>

当jetty启动时,它没有为类WebAppContext说setErrorHandler这样的方法,(我在其父类ErrorHandler中找到了setErrorHandler方法,所以我认为它确实意味着)

然后创建一个文件'error-handler-context.xml'并填写文件:

<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
  <Set name="contextPath">/</Set>   
  <Set name="errorHandler">
     <New class="com.mobile.service.handlers.ServerErrorPageErrorHandler"/>
   </Set> 
</Configure>

然后jetty成功启动,但错误处理程序没有效果 .

我只想将错误页面“Power by jetty”中显示的消息更改为“Power by OWN SERVER” .

而且我不想创建新的错误页面 .

那怎么实现呢?

我像这样更改配置文件:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
   <Set name="contextPath">/</Set>
      <Call name="setErrorHandler">
        <Arg>
            <New class="com.hp.mobile.service.handlers.ServerErrorPageErrorHandler"/>
       </Arg>
     </Call>

</Configure>

在jetty启动之后,仍然会说NoSuchMethod'setErrorHanlder'异常,

我调试它,并获得异常:

“java.lang.illegalargumentexception:参数类型不匹配”

在“TypeUtil.java”中的method.invoke(obj,arg)

setErrorHandler的参数是ErrorHandler类,

就我而言,它是从ErrorHandler扩展而来的,

那为什么会发生?

BTW:我还将类ServerErrorPageErrorHandler更改为从ErrorHandler扩展,它也不起作用 .