WEB언어

HTTP charset parameter 값 처리

saltdoll 2010. 9. 3. 15:32
반응형


Setting the HTTP charset parameter
The line in the HTTP header typically looks like this:
   
     Content-Type: text/html; charset=utf-8

Server setup
Apache Setting charset .htaccess : http://www.w3.org/International/questions/qa-htaccess-charset
AddCharset(Apache 1.3.10 and later) or AddType
AddDefaultCharset(Apache 1.3.12 and later)

IIS 5 and 6. In Internet Services Manager, right-click "Default Web Site" (or the site you want to configure) and go to "Properties" => "HTTP Headers" => "File Types..." => "New Type...". Put in the extension you want to map, separately for each extension; IIS users will probably want to map .htm, .html,... Then, for Content type, add "text/html;charset=iso-8859-1" (without the quotes; substitute your desired charset for iso-8859-1; do not leave any spaces anywhere because IIS ignores all text after spaces). For IIS 4, you may have to use "HTTP Headers" => "Creating a Custom HTTP Header" if the above does not work.

Scripting the header

Perl. Output the correct header before any part of the actual page. After the last header, use a double linebreak, e.g.:
print "Content-Type: text/html; charset=utf-8\n\n";

Python. Use the same solution as for Perl (except that you don't need a semicolon at the end).

PHP. Use the header() function before generating any content, e.g.:
header('Content-type: text/html; charset=utf-8');

Java Servlets. Use the setContentType method on the ServletResponse before obtaining any object (Stream or Writer) used for output, e.g.:
resource.setContentType ("text/html;charset=utf-8");
If you use a Writer, the Servlet automatically takes care of the conversion from Java Strings to the encoding selected.

JSP. Use the page directive e.g.:
<%@ page contentType="text/html; charset=UTF-8" %>
Output from out.println() or the expression elements (<%= object%>) is automatically converted to the encoding selected. Also, the page itself is interpreted as being in this encoding.

ASP and ASP.Net. content type and charset are set independently, and are methods on the response object. To set the charset, use e.g.:
<%Response.charset="utf-8"%>
In ASP.Net, setting Response.ContentEncoding will take care both of the charset parameter in the HTTP Content-Type as well as of the actual encoding of the document sent out (which of course have to be the same). The default can be set in the globalization element in Web.config (or Machine.config, which is originally set to UTF-8).




W3C 출처: http://www.w3.org/International/O-HTTP-charset
반응형
도움이 되셨다면 하트모양의 "♡ 공감"을 눌러주시면 큰 격려가 됩니다.
(로그인하지 않으셔도 가능)