How does a Java application server decide what charset to send in the HTTP Content-type header?
In my current project, I've been forgetting about character encoding and just letting the application server do the right thing. This was working fine for some time. For instance, I was able to switch the locale in my application to Simplified Chinese / China and see the UTF-8 characters just fine in any recent Firefox or Chrome browser. Something changed (I'm still trying to figure out what). Content is still UTF-8 encoded, but sometimes the Content-type header is setting the charset wrong:
Content-Type:text/html;charset=ISO-8859-1
...leadi开发者_C百科ng to garbage appearing in the browser instead of Chinese characters. If I temporarily force the encoding to UTF-8 in my browser, the characters show up properly.
What would really help nail down the problem is knowing how an application server (or Web dev framework like struts or spring?) decides what to put in this header! Any ideas?
What web technology are you using? For instance in servlets you have ServletResponse#setCharacterEncoding(). In JSP:
<%@ page contentType="text/html; charset=UTF-8" %>
Eventually every web framework will end up using one of the two above.
精彩评论