通用错误页面未装饰 [英] Generic Error Page not decorated
问题描述
我可以知道是什么原因?
< filter>
< display-name> SiteMesh_Filter< / display-name>
< filter-name> SiteMesh_Filter< / filter-name>
< filter-class> com.opensymphony.module.sitemesh.filter.PageFilter< / filter-class>
< / filter>
< filter-mapping>
< filter-name> SiteMesh_Filter< / filter-name>
< url-pattern> / *< / url-pattern>
< / filter-mapping>
< error-page>
< error-code> 404< / error-code>
< location> /pages/error.jsp< / location>
< / error-page>
谢谢。
我将假设您正在使用Sitemesh 3作为装饰器。您的配置中的问题告诉我您正在使用Sitemesh 2,但是您提到在对@kschneid答案的评论中使用Sitemesh 3。
Sitemesh 3使用选择器
实现来选择可以缓冲(装饰)的请求。默认情况下,这是 org.sitemesh.webapp.contentfilter.BasicSelector
。这个选择器有两个构造函数:
public BasicSelector(String ... mimeTypesToBuffer){
this(false,mimeTypesToBuffer ); b
$ b public BasicSelector
this.includeErrorPages = includeErrorPages;
}
前者由 BaseSiteMeshFilterBuilder
默认构造选择器。这意味着 includeErrorPages
属性将被设置为 false
,只有状态为 200的页面OK 将被过滤器缓冲。为了克服这个问题,您将需要以某种方式使用其他构造函数,并将 includeErrorPages
设置为 true
。
这可以通过子类化 org.sitemesh.config.ConfigurableSiteMeshFilter
并覆盖受保护的 applyCustomConfiguration(SiteMeshFilterBuilder builder)
方法以类似于以下方法结束:
public class ErrorPageEnabledSiteMeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder){
builder.setCustomSelector(new BasicSelector(true,text / html,application / xhtml + xml,application / vnd.wap.xhtml + xml))
}
}
以上将指示构建器使用现在将装饰错误页面的自定义选择器。唯一剩下的是将 ErrorPageEnabledSiteMeshFilter
的实例添加到您的 ServletContext
中,替换旧的。
I have a generic error page which is not decorated by SiteMesh.
May I know what is the reason ?
<filter>
<display-name>SiteMesh_Filter</display-name>
<filter-name>SiteMesh_Filter</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SiteMesh_Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<error-page>
<error-code>404</error-code>
<location>/pages/error.jsp</location>
</error-page>
Thanks.
I'm going to assume you're using Sitemesh 3 as a decorator. Your configuration in the questions tells me you're using Sitemesh 2, but you mentioned using Sitemesh 3 in the comment to @kschneid answer.
Sitemesh 3 uses a Selector
implementation to select which requests it can buffer (decorate). By default this is the org.sitemesh.webapp.contentfilter.BasicSelector
. This selector has two constructors namely:
public BasicSelector(String... mimeTypesToBuffer) {
this(false, mimeTypesToBuffer);
}
public BasicSelector(boolean includeErrorPages, String... mimeTypesToBuffer) {
this.mimeTypesToBuffer = mimeTypesToBuffer;
this.includeErrorPages = includeErrorPages;
}
The former is used by the BaseSiteMeshFilterBuilder
to construct the selector by default. This means the includeErrorPages
property will be set to false
and only pages with a status of 200 OK will be buffered by the filter. To overcome this you will need to somehow use the other constructor and set includeErrorPages
to true
.
This can be done by subclassing org.sitemesh.config.ConfigurableSiteMeshFilter
and override the protected applyCustomConfiguration(SiteMeshFilterBuilder builder)
method ending up with a method similar to:
public class ErrorPageEnabledSiteMeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
builder.setCustomSelector(new BasicSelector(true, "text/html", "application/xhtml+xml", "application/vnd.wap.xhtml+xml"))
}
}
The above will instruct the builder to use the custom selector which now will decorate error pages. The only thing left is to add a instance of ErrorPageEnabledSiteMeshFilter
to your ServletContext
replacing the old one.
这篇关于通用错误页面未装饰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!