You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Clement Low <tr...@gmail.com> on 2008/09/21 16:57:07 UTC
Adding custom http headers to pages that my Tomcat serve
Hi all,
I would like to set a custom header to all of the pages that my Tomcat serve
:
*<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />*
What this does is basically telling IE 8 to display the particular page as
if it were in IE 7.
I do not want to add this header to every page that I have. What can I do to
tell Tomcat to achieve this?
Thank you.
Re: Adding custom http headers to pages that my Tomcat serve
Posted by André Warnier <aw...@ice-sa.com>.
André Warnier wrote:
[...]
I wanted to add something to my previous hypothesis that
>
> I believe that, in theory, the <meta http-equiv="xxxx" content="yyyy"
> ... > tag in the html document, should have the same effect as if the
> server, in the HTTP headers of the response, had sent a header like
> xxxx: yyyy
> before sending the actual content of the html page.
>
The reference here
http://www.w3.org/TR/REC-html40/struct/global.html#h-7.4.4.2
seems to say that it is the other way around :
If the (html) document contains a tag
<meta http-equiv="xxxx" content="yyyyy" ..>
then the HTTP server (presumably by scanning the document prior to
sending it to the client) *might* use the content of this tag to add an
additional HTTP header to the response sent to the client.
Now, this would suppose that the HTTP server (Tomcat in this case)
1) scans the html pages going out before starting the response
2) effectively adds a HTTP header when it finds ditto tag above in the
html document header.
Neither of which I am sure of. Gurus ?
The next questions would be :
1) when IE receives the response from the HTTP server, does it
effectively take into account a HTTP response header like
X-UA-Compatible: IE=EmulateIE7
or does it ignore it ?
On past form, IE has a tendency to ignore a lot of things the server is
telling it, and using its own obscure logic to second-guess the server.
2) If IE does not take the HTTP server's HTTP header
X-UA-Compatible: IE=EmulateIE7
into account, does it itself then interpret the <meta > tag in the html
document ?
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Adding custom http headers to pages that my Tomcat serve
Posted by André Warnier <aw...@ice-sa.com>.
Mikolaj Rydzewski wrote:
> Clement Low wrote:
>> I would like to set a custom header to all of the pages that my Tomcat
>> serve
>> :
>>
>>
>> *<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />*
>>
>>
>> What this does is basically telling IE 8 to display the particular
>> page as
>> if it were in IE 7.
>>
>> I do not want to add this header to every page that I have. What can I
>> do to
>> tell Tomcat to achieve this?
>>
> The better way is to implement a servlet filter and declare it in
> application's web.xml descriptor.
>
Hi.
I believe that, in theory, the <meta http-equiv="xxxx" content="yyyy"
... > tag in the html document, should have the same effect as if the
server, in the HTTP headers of the response, had sent a header like
xxxx: yyyy
before sending the actual content of the html page.
In other words, in your case, adding to the HTTP response a HTTP header
like :
X-UA-Compatible: IE=EmulateIE7
should do the trick.
I have never tried the above, and I am not sure about it, but if it
turns out to be true, then there should be more than one possibility to
achieve what you want, in the order easiest first :
1) find an existing Tomcat add-on module (a filter) which is capable of
adding a HTTP header to the responses of Tomcat.
I suggest to have a look here :
http://tuckey.org/urlrewrite/
and further here :
http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/3.1/index.html
Look at the <set> element, with type="response-header".
That module (urlrewrite) is a servlet filter, and can do a wide variety
of things, and adding an outgoing HTTP header is among what it can do.
2) If that does not work for you, then you could write your own servlet
filter, to do the same (adding a HTTP header to the response).
It is not a very complicated servlet filter to write, and there are
probably some examples and tutorials floating around.
3) If that in the end does not work (meaning I amwrong, and the trick of
adding this as a HTTP header does not work at all), then you would need
a filter which scan and modifies each html response page, to insert this
<meta ..> tag.
I believe that this is a lot less efficient than merely adding a HTTP
header, which is the reason why I put this solution only in third place.
But basically, that is what most Content Management and templating
systems systems do, so it cannot be so bad.
In that case, again you have a choice :
3a) find an existing servlet filter which does that.
3b) write your own servlet filter to do it.
It also does not sound extremely complicated, because you merely want to
insert the same string into any outgoing html document.
But I am sure that you will find some complications on the way.
I believe that if the only thing you want to do is to add the meta tag,
to *all* outgoing pages, 3b) may then anyway be your best bet,
efficiency-wise, because it is likely that any solution you will find
for 3a) will probably do a lot more, and thus be a lot heavier.
On the other hand, maybe it would be useful in the end to be able to do
a lot more, and maybe efficiency is not very important in this case.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Adding custom http headers to pages that my Tomcat serve
Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
Clement Low wrote:
> I would like to set a custom header to all of the pages that my Tomcat serve
> :
>
>
> *<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />*
>
>
> What this does is basically telling IE 8 to display the particular page as
> if it were in IE 7.
>
> I do not want to add this header to every page that I have. What can I do to
> tell Tomcat to achieve this?
>
The better way is to implement a servlet filter and declare it in
application's web.xml descriptor.
--
Mikolaj Rydzewski <mi...@ceti.pl>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org