[英]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.
例如,我能够将我的应用程序中的语言环境切换到简体中文/中国,并在任何最近的Firefox或Chrome浏览器中看到UTF-8字符。 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 :
内容仍然是UTF-8编码,但有时Content-type标头设置charset错误 :
Content-Type:text/html;charset=ISO-8859-1
...leading 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.
如果我在浏览器中暂时强制编码为UTF-8,则字符会正确显示。
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! 真正有助于解决问题的是知道应用程序服务器(或像struts或spring的Web开发框架?)如何决定放入此标头的内容! Any ideas?
有任何想法吗?
What web technology are you using? 你使用什么网络技术? For instance in servlets you have ServletResponse#setCharacterEncoding() .
例如,在servlet中,您有ServletResponse #setCharacterEncoding() 。 In JSP:
在JSP中:
<%@ page contentType="text/html; charset=UTF-8" %>
Eventually every web framework will end up using one of the two above. 最终,每个Web框架最终都将使用上述两个中的一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.