更改HttpServletResponse的编码 [英] Change encoding of HttpServletResponse
问题描述
我的问题是:有一个简单的方法吗?我可以在电话完成之前访问响应,所以我想知道我是否可以做一些像
//这个方法不存在
response.setCharacterEncoding(UTF-16LE);
非常感谢!
更新:
提到的方法是使用的方法。我使用的是没有包含它的servlet API的旧版本(2.3)。
呃,方法有存在, here
设置发送给客户端
的响应的字符编码(MIME
charset),for例如UTF-8。如果
,字符编码已经由
setContentType(java.lang.String)或
setLocale(java.util.Locale)设置,
方法覆盖它。调用
setContentType(java.lang.String)与
文本/ html的字符串并调用
此方法与UTF-8的字符串
相当于调用
setContentType,字符串为
text / html; charset = UTF-8。
I have an API that returns XML, it actually returns it using the default encoding (I believe it's UTF-8), but now requirements have changed and we need to return everything in UTF-16LE.
My question is: is there an easy way of doing this? I have access to the response just before the calls complete so I was wondering if I could do something like
//This method does not exist
response.setCharacterEncoding("UTF-16LE");
Thanks a lot!
UPDATE: The method mentioned is the one to use. I was using an old version (2.3) of the servlet API that did not include it. Changing the version fixed it all.
Uhh, the method does exist, here
Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8. If the character encoding has already been set by setContentType(java.lang.String) or setLocale(java.util.Locale), this method overrides it. Calling setContentType(java.lang.String) with the String of text/html and calling this method with the String of UTF-8 is equivalent with calling setContentType with the String of text/html; charset=UTF-8.
这篇关于更改HttpServletResponse的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!