tomcat错误页面使用检票口中的可书签页面



我有这样一个问题。

接收404 HTTP错误时,我需要显示自定义错误页面。我使用的是检票口1.4和tomcat6。我已经在web.xml中实现了这些东西,例如

 <filter-name>wicket.filter</filter-name>
    <url-pattern>/*</url-pattern>         
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
 </filter-mapping>
<error-page>
    <error-code>404</error-code>
    <location>/404</location>
</error-page>

并将此类代码放在我的WebApplication中:

mount(new HybridUrlCodingStrategy("/404", PageNotFound.class));

pagenotfound类isErrorPage set true,isversed false和

    @Override
    protected void configureResponse() {
       super.configureResponse();   
       getWebRequestCycle().getWebResponse().getHttpServletResponse().setStatus(HttpServletResponse.SC_NOT_FOUND);
    }

现在的问题是,当我输入一些无效的URL(例如http://localhost:8080/myApp-war/invalidUrl)时,我可以看到我的Pagenotfound。但是,当我输入诸如http://localhost:8080/myApp-war/?wicket:bookmarkablePage=:com.mypackage.invalidUrl之类的内容时,我只会获得空的清除页面而没有任何数据。

我注意到,最初的情况tomcat只是显示" http状态404-/myapp -war/invalidurl "在另一种情况下,它显示的消息略有不同:" http状态404-无法加载书签页"

如何使两个案例显示同一页面?也许需要修改此<error-page>标签?如果您需要,我将为您提供更多信息。

您的代码和您的期望是完美的。这只是对404例外的检票口错误或tomcat错误的理解。我想它只是在1.4.x版本之前的检票口。

修复程序是覆盖 avstractreqtrequrestcycleprocessor 中的代码,您只需在WebApplication类的出厂方法中覆盖它:

@Override
protected IRequestCycleProcessor newRequestCycleProcessor() {
return new WebRequestCycleProcessor() {
    @Override
    protected IRequestTarget resolveBookmarkablePage(final RequestCycle requestCycle,
            final RequestParameters requestParameters) {
        IRequestTarget target = super.resolveBookmarkablePage(requestCycle, requestParameters);
        if(target == null) {
            return target;
        }
        if(target instanceof WebErrorCodeResponseTarget) {
            WebErrorCodeResponseTarget errorResponse = (WebErrorCodeResponseTarget) target;
            if(HttpServletResponse.SC_NOT_FOUND == errorResponse.getErrorCode()) {
                return null;
            }
        }
        return target;
    }
};

}

我将完整的工作示例放入我的Wicket14测试存储库https://repo.twinstone.org/projects/wistf/repos/wicket-examples-1.4/browse-browse

最新更新