java 配置Tomcat发送兼容IE 7或6的网页

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2810271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 22:57:41  来源:igfitidea点击:

Configure Tomcat to send web pages compatible to IE 7 or 6

javahttpinternet-explorer-8tomcat5.5

提问by Spiderman

I have got an application that is not compatible to work using IE8 browser.

我有一个与使用 IE8 浏览器不兼容的应用程序。

I am looking for a way to to configure Tomcat on which this application run, so the pages could be read by IE8 and treated as if they are IE7 or IE6

我正在寻找一种方法来配置运行此应用程序的 Tomcat,以便 IE8 可以读取页面并将它们视为 IE7 或 IE6

By googling so far I found a possible suggestion which say to add to the http response the header: X-UA-Compatible: IE=EmulateIE7
here

到目前为止,通过谷歌搜索,我发现了一个可能的建议,即在 http 响应中添加标头: X-UA-Compatible: IE=EmulateIE7
here

that tell IE8 to be like IE7.

告诉 IE8 就像 IE7。

The problem is that this way requires adding a filter that should be added on application level. I'd like to know if any of you is familiar with a more generic way that Tomcat enables to send its http content to be IE7 (or IE6) compatible ?

问题是这种方式需要添加一个应该在应用程序级别添加的过滤器。我想知道你们中是否有人熟悉 Tomcat 能够将其 http 内容发送到 IE7(或 IE6)兼容的更通用的方式?

采纳答案by Juriy

Tomcat is a general purpose webserver and servlet container. It is absolutely browser-agnostic thus, there's no way to configure it in some special way to deal with IEs.

Tomcat 是一个通用的网络服务器和 servlet 容器。它绝对与浏览器无关,因此无法以某种特殊方式配置它来处理 IE。

You don't have to add filter really. The bare minimum is to set the response header anywhere in "service" method (or doGet or doPost, whatever application uses):

您实际上不必添加过滤器。最低限度是在“服务”方法(或 doGet 或 doPost,无论应用程序使用什么)中的任何位置设置响应头:

res.addHeader("X-UA-Compatible", "IE=EmulateIE7 ");

res.addHeader("X-UA-Compatible", "IE=EmulateIE7");

But this is in case when there's a single entry point in the server application. Otherwise filter should do the job in a better way.

但这是在服务器应用程序中只有一个入口点的情况下。否则过滤器应该以更好的方式完成工作。

回答by Jonny Alexander

  1. Download urlrewritefilter-4.0.3.jar from http://tuckey.org/urlrewrite/
  2. Add urlrewritefilter-4.0.3.jar to WEB-INF/lib
  3. Add following code to WEB-INF/web.xml
  1. http://tuckey.org/urlrewrite/下载 urlrewritefilter-4.0.3.jar
  2. 将 urlrewritefilter-4.0.3.jar 添加到 WEB-INF/lib
  3. 将以下代码添加到 WEB-INF/web.xml
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
  1. Make a new configuration file for the module. (WEB-INF/urlrewrite.xml)
  1. 为模块创建一个新的配置文件。(WEB-INF/urlrewrite.xml)
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN" "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
<urlrewrite>
<rule><condition name="user-agent">.*MSIE.*</condition>
<set type="response-header" name="X-UA-Compatible">IE=EmulateIE7</set>
</rule>
</urlrewrite>

回答by kgiannakakis

See this forum threadthat discusses exactly the same situation you are describing. It seems that a filter is the best way to go. As an answer at the above thread suggests, you could use Url Rewrite Filter.

请参阅此论坛主题,该主题讨论的情况与您所描述的情况完全相同。似乎过滤器是最好的方法。正如上述线程的答案所暗示的那样,您可以使用Url Rewrite Filter

Also, if you are using Apache Web Server to proxy Tomcat, you could easily configure it to add any header to the response.

此外,如果您使用 Apache Web Server 来代理 Tomcat,您可以轻松地将其配置为向响应添加任何标头。