Search code examples
javahtmlhttpcharacter-encodingurl-encoding

Is GET Query String affected by content='text/html; charset=gb2312' html meta tag attribute?


The Question is,

In a regular HTTP Request to a server (non-ajax), Is the Query String passed by GET method to some server, get affected by the encoding specified by this :

<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>

If the answer is no, How to define the encoding schema for the parameters of GET method ?

example: If I have a html that looks:

<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
</head>
<body>
 <form method="GET" action="/some/server">
  <input type="text" name="name1" value="someNon-ASCII_value1" />
  <input type="submit" />
 </form>
</body>
<html>

When the user click the submit button, what will be the encoding of the value someNon-ASCII_value1 ?


Solution

  • The browser will use the same encoding as it was been instructed to use to display the page with the form. This can indeed be the encoding as specified in the meta content-type entry in the HTML head, but this can be overridden by a content-type header in the HTTP response.

    You however also need to take into account the correct URL encoding in the server side to decode the GET parameters. It's unclear which server you're using, but in case of for example Tomcat you need to set the URIEncoding attribute of the <Connector> element to the same encoding.

    <Connector ... URIEncoding="gb2312">
    

    Also see this article for more background information.