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

↘锁芯ラ 提交于 2019-12-08 03:45:04

问题


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

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

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

that tell IE8 to be like 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 ?


回答1:


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.

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):

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.




回答2:


  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
<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)
<?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>



回答3:


See this forum thread that 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.

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



来源:https://stackoverflow.com/questions/2810271/configure-tomcat-to-send-web-pages-compatible-to-ie-7-or-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!