本文介绍了更改HttpServletResponse的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回XML的API,它实际上使用默认的编码返回它(我相信它是UTF-8),但是现在的需求已经改变了,我们需要返回所有的UTF-16LE。



我的问题是:有一个简单的方法吗?我可以在电话完成之前访问响应,所以我想知道我是否可以做一些像

  //这个方法不存在
response.setCharacterEncoding(UTF-16LE);

非常感谢!



更新:
提到的方法是使用的方法。我使用的是没有包含它的servlet API的旧版本(2.3)。

解决方案

呃,方法存在,


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

这篇关于更改HttpServletResponse的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 08:03
查看更多