You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Luogang Wang <yt...@gmail.com> on 2011/07/23 03:11:26 UTC

html meta http-equiv content-type not work ?

hi,

my tomcat version 7.0.16 ;

I put this simple html on tomcat webapps ROOT directory.

<!doctype html>
<html>
 <head>
  <title> New Document </title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 </head>
 <body>
  hello world!
 </body>
</html>

when request the file from browser ,the http response not have the header
of "Content-type:text/html; charset=UTF-8" , just  "Content-type:text/html";

I think it should have the charset parameter , why not ? http-equiv not work
on tomcat ?

thanks!
ytuwlg

Re: html meta http-equiv content-type not work ?

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/7/23 Mark Thomas <ma...@apache.org>:
> On 23/07/2011 02:11, Luogang Wang wrote:
>> hi,
>>
>> my tomcat version 7.0.16 ;
>>
>> I put this simple html on tomcat webapps ROOT directory.
>>
>> <!doctype html>
>> <html>
>>  <head>
>>   <title> New Document </title>
>>   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
>>  </head>
>>  <body>
>>   hello world!
>>  </body>
>> </html>
>>
>> when request the file from browser ,the http response not have the header
>> of "Content-type:text/html; charset=UTF-8" , just  "Content-type:text/html";
>>
>> I think it should have the charset parameter , why not ? http-equiv not work
>> on tomcat ?
>
> Tomcat does not scan static content for meta tags. If you want to set
> the charset in the HTTP header, you'll need to set it explicitly using a
> JSP, a filter or similar.
>

or if all static HTML files have the same charset you can configure it in
mime-mapping element in your WEB-INF/web.xml

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: html meta http-equiv content-type not work ?

Posted by Marvin Addison <ma...@gmail.com>.
> I think you mean "any attempt to WRITE The RESPONSE".

I took some time to verify the effect I described,
https://github.com/serac/charset-test.  Reading data from the request
body coerces the encoding as I claimed.  Simply swap the order of the
filter-mappings in web.xml and post some unicode data to see for
yourself.  If ConsumeRequestFilter appears before
CharacterEncodingFilter, the posted data will not be treated as UTF-8.

> Spring's filter only sets the /request/ encoding, not the response.

Looks like it sets response encoding when forceEncoding == true:

		if (this.encoding != null && (this.forceEncoding ||
request.getCharacterEncoding() == null)) {
			request.setCharacterEncoding(this.encoding);
			if (this.forceEncoding) {
				response.setCharacterEncoding(this.encoding);
			}
		}

(3.0.5 source)

M

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: html meta http-equiv content-type not work ?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



On 7/23/2011 8:34 AM, Marvin Addison wrote:
>> If you want to set the charset in the HTTP header, you'll need to 
>> set it explicitly using a JSP, a filter or similar.
> 
> It's wise to do both, 
> http://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q8.
> 
> For the filter, it's important to put the filter at or near the top 
> of the filter chain since any attempt to read the request will
> coerce the encoding, possibly before it is explicitly set.

I think you mean "any attempt to WRITE The RESPONSE".

> Two good existing filters for this purpose:
> 
> http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/filter/CharacterEncodingFilter.html

Spring's
> 
filter only sets the /request/ encoding, not the response.

> http://code.google.com/p/vt-middleware/wiki/vtservletfilters#CharacterEncodingFilter

The
> 
above will set response encoding too.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4tn6IACgkQ9CaO5/Lv0PDr3wCfZ/cmBGib/o1lfLcRceLBYFof
KnYAniUd2AAqEVnb+sC9L6rSuhVXUspw
=68m4
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: html meta http-equiv content-type not work ?

Posted by Marvin Addison <ma...@gmail.com>.
> If you want to set
> the charset in the HTTP header, you'll need to set it explicitly using a
> JSP, a filter or similar.

It's wise to do both, http://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q8.  For the filter, it's important to put the filter at or near the top of the filter chain since any attempt to read the request will coerce the encoding, possibly before it is explicitly set.  Two good existing filters for this purpose:

http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/filter/CharacterEncodingFilter.html

http://code.google.com/p/vt-middleware/wiki/vtservletfilters#CharacterEncodingFilter

M


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: html meta http-equiv content-type not work ?

Posted by Mark Thomas <ma...@apache.org>.
On 23/07/2011 02:11, Luogang Wang wrote:
> hi,
> 
> my tomcat version 7.0.16 ;
> 
> I put this simple html on tomcat webapps ROOT directory.
> 
> <!doctype html>
> <html>
>  <head>
>   <title> New Document </title>
>   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
>  </head>
>  <body>
>   hello world!
>  </body>
> </html>
> 
> when request the file from browser ,the http response not have the header
> of "Content-type:text/html; charset=UTF-8" , just  "Content-type:text/html";
> 
> I think it should have the charset parameter , why not ? http-equiv not work
> on tomcat ?

Tomcat does not scan static content for meta tags. If you want to set
the charset in the HTTP header, you'll need to set it explicitly using a
JSP, a filter or similar.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org