将元标记添加到 Webspehere 门户中 JSR 286 portlet 的 head 元素

发布于 2024-12-11 16:11:02 字数 973 浏览 2 评论 0原文

我们开发了 JSR 286 portlet。在 IE8 中加载 JSP 页面时,我们遇到一些对齐问题,导致屏幕无法正确加载。

我们可以看出,这是因为 IE 8 兼容性问题。默认情况下,页面在 IE8 中以 Quirks 模式加载。如果我们将模式更改为 IE8 标准,我们就可以看到页面加载,没有任何问题。我发现我们可以设置一个元 " 来从 JSP 启用 IE8 标准模式但是

如何将元标记添加到 portlet 页面的 head 元素中?我的 Web 应用程序中的 标记将从 portlet 容器生成,如何将元标记添加到我

尝试覆盖 doHeader 的 head 元素?方法也如下,

protected void doHeaders(RenderRequest request, RenderResponse response) {
    Element metaKeywords = response.createElement("meta");
    metaKeywords.setAttribute("http-equiv", "X-UA-Compatible");
    metaKeywords.setAttribute("content", "IE=EmulateIE8");
    // response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, ""); - I tried this option   also
   //response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, metaKeywords); - I tried this option also
}

但没有任何结果。

我们的应用程序在 WAS 7.0 上运行。

任何人都可以指点一下吗?

We have developed JSR 286 portlet. While loading the JSP page in IE8, we are facing some alignment issues due to which our screen is not loading properly.

We could figure out that, it is because of the IE 8 compatibility issue. By default the page loads in Quirks mode in IE8. If we change the mode to IE8 Standard, we are able to see the page loading without any issue. I could find that we can set a meta <meta http-equiv='X-UA-Compatible' content='IE=EmulateIE8' />" for enabling the IE8 standard mode from the JSP.

But how can I add the meta tag into the head element of the portlet page? Since I dont have the <html>, <head> and <body> tags in my web application and it will be generated from the portlet container, how can I add the meta tag to the head element?

I tried overriding the doHeader method also as follows

protected void doHeaders(RenderRequest request, RenderResponse response) {
    Element metaKeywords = response.createElement("meta");
    metaKeywords.setAttribute("http-equiv", "X-UA-Compatible");
    metaKeywords.setAttribute("content", "IE=EmulateIE8");
    // response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, ""); - I tried this option   also
   //response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, metaKeywords); - I tried this option also
}

But nothing worked out.

Our application is running on WAS 7.0.

Can anyone give some pointers ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好吧,这对OP来说不再有用,但这是答案。

可以在 portlet 的“渲染生命周期阶段”完成此操作 - 用更普通的术语来说,可以通过重写 GenericPortlet.doHeaders() 来完成此操作:

public class MyPortlet extends GenericPortlet {

    @Override
    public void doHeaders(RenderRequest req, RenderResponse res)
    throws PortletException {
        Element meta = response.createElement("meta");

        meta.setAttribute("http-equiv", "X-UA-Compatible");
        meta.setAttribute("content", "IE=EmulateIE8");

        response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, meta);
    }
}

您可能必须在以下位置设置一个容器运行时选项 :如果您的门户是流门户,则为 portlet.xml:(

<portlet>
    <container-runtime-option>
        <name>javax.portlet.renderHeaders</name>
        <value>true</value>
    </container-runtime-option>
</portlet>

有关流门户与缓冲门户的更多信息,以及一个很好的代码示例,此处。)

此外,请注意,如果门户认为您的元素是安全风险,但直到现在我才遇到问题。

我还没有测试这个特定的代码,但做了类似的事情(至少在冥王星上)并且它有效。因此,这些可能是很好的起点。

注意:JSR-362 (Portlet 3.0) 将为此提供一个完整的 portlet 生命周期阶段,HEADER_PHASE。在这种情况下,只需实现 renderHeaders(HeaderRequest, HeaderResponse) 即可。但这个规范还只是草案。

Ok, this is not going to be useful to the OP anymore, but here is the answer.

One can can do it at the "render lifecycle phase" of the portlet — in more mundane terms, one can do it by overriding GenericPortlet.doHeaders():

public class MyPortlet extends GenericPortlet {

    @Override
    public void doHeaders(RenderRequest req, RenderResponse res)
    throws PortletException {
        Element meta = response.createElement("meta");

        meta.setAttribute("http-equiv", "X-UA-Compatible");
        meta.setAttribute("content", "IE=EmulateIE8");

        response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, meta);
    }
}

You may have to set a container runtime option on your portlet.xml if your portal is a streaming portal:

<portlet>
    <container-runtime-option>
        <name>javax.portlet.renderHeaders</name>
        <value>true</value>
    </container-runtime-option>
</portlet>

(More about streaming vs. buffering portals, and a good code example, here.)

Also, note the portal is free to ignore your element if it considers it to be a security risk, but I did not have problems with that until now.

I have not tested this specific code, but have did something similar (on Pluto at least) and it worked. So, those can be good starting points.

NOTE: JSR-362 (Portlet 3.0) will have an entire portlet lifecycle phase for that, HEADER_PHASE. In this case, one just needs to implement renderHeaders(HeaderRequest, HeaderResponse). But this spec is a draft yet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文