Tomcat Servlet FileUpload and UTF-8
I am using commons FileUpload to get client headers. I am trying to use the header Strings to write txt content like:
StringA; StringB; "ciryllic word"
The server localization is ru_RU.utf-8 the client is cp1251... The result is I always get on my client (desktop app)
StringA; StringB; ?????
instead of cyrillic characters in my server txt files lines. If I open txt开发者_开发技巧 with my IE 8 and watch the encoding the cyrillic content can be readable with utf-8 encoding only :( So my question is what should me do to make my servlet write ru_RU.utf-8 acceptable strings. I am testing it on windows so I need to know it for sure
Please help me to understand
Any useful comment is appreciated
ServletOutputStream out =response.getOutputStream();
out.write((YOUrfileasstring).getBytes("UTF-8"));
I might be misunderstanding the question, but to answer this part -
So my question is what should me do to make my servlet write ru_RU.utf-8 acceptable strings.
You should use either of two methods provided by the HttpServletResponse class. Those are:
setContentType(), e.g.
response.setContentType("text/html; charset=UTF-8");
or,
setCharacterEncoding(), e.g.
response.setCharacterEncoding("utf-8");
There are other examples for those methods and information on when to use them all over the place.
精彩评论