Wicket标题贡献与html中的元数据

时间:2014-02-26 10:25:07

标签: java wicket

我使用Wicket 6.6.0并升级到6.14.0。在WicketApplication中,我在init() - Method

中有以下代码
getHeaderContributorListenerCollection().add(new IHeaderContributor() {

        private static final long serialVersionUID = 442899940490126649L;

        @Override
        public void renderHead(final IHeaderResponse response) {
            response.render(WicketUtils.composeMetaItem("X-UA-Compatible", "IE=edge"));
            response.render(WicketUtils.composeMetaItem("Content-Type", "text/html; charset=UTF-8"));
            response.render(WicketUtils.composeMetaItem("Expires", "0"));
            response.render(WicketUtils.composeMetaItem("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, private"));
            response.render(WicketUtils.composeMetaItem("Pragma", "no-cache"));
        }
    });

在html头中呈现元数据。

这导致在更新Wicket 6.14.0之后,Wicket调试器在我执行ajax请求后抛出错误。如果删除了上述代码,则不会抛出该错误。

错误如下:

ERROR: Error in parsing: This page contains the following errors:error on line 22 at column 8: Opening and ending tag mismatch: meta line 0 and head

下面是第一个错误之前的页面呈现。

是否可以将上述元数据放在HTML中,会有什么区别?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<wicket:head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, max-age=0, private">
    <meta http-equiv="Pragma" content="no-cache">   
</wicket:head>
...
</html>

1 个答案:

答案 0 :(得分:0)

Wicket 8 (以及7和6.17 +)中,可以通过以下方式添加MetaDataHeaderItem元标记:

public class BasePage extends WebPage {

    @Override
    public void renderHead(IHeaderResponse response) {
        super.renderHead(response);

        response.render(MetaDataHeaderItem.forMetaTag("X-UA-Compatible", "IE=edge"));
        response.render(MetaDataHeaderItem.forMetaTag("Content-Type", "text/html; charset=UTF-8"));
        response.render(MetaDataHeaderItem.forMetaTag("Expires", "0"));
        response.render(MetaDataHeaderItem.forMetaTag("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, private"));
        response.render(MetaDataHeaderItem.forMetaTag("Pragma", "no-cache"));
    }
}

它将产生以下输出:

<meta name="X-UA-Compatible" content="IE=edge" />
<meta name="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Expires" content="0" />
<meta name="Cache-Control" content="no-store, no-cache, must-revalidate, max-age=0, private" />
<meta name="Pragma" content="no-cache" />