将元标记添加到 Webspehere 门户中 JSR 286 portlet 的 head 元素
我们开发了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这对OP来说不再有用,但这是答案。
可以在 portlet 的“渲染生命周期阶段”完成此操作 - 用更普通的术语来说,可以通过重写 GenericPortlet.doHeaders() 来完成此操作:
您可能必须在以下位置设置一个容器运行时选项 :如果您的门户是流门户,则为 portlet.xml:(
有关流门户与缓冲门户的更多信息,以及一个很好的代码示例,此处。)
此外,请注意,如果门户认为您的元素是安全风险,但直到现在我才遇到问题。
我还没有测试这个特定的代码,但做了类似的事情(至少在冥王星上)并且它有效。因此,这些可能是很好的起点。
注意: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()
:You may have to set a container runtime option on your portlet.xml if your portal is a streaming portal:
(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 implementrenderHeaders(HeaderRequest, HeaderResponse)
. But this spec is a draft yet.