I' ve a Spring MVC bean and I would like to return turkish character by setting encoding UTF-8. but although my string is "??????????üü" it returns as "??????????üü". and also when I look at the response page, which is internet explorer page, encoding is western european iso, not UTF-8.
Here is the code:
@RequestMapping(method=RequestMethod.GET,value="/GetMyList")
public @ResponseBody String getMyList(HttpServletRequest request, HttpServletResponse response) throws CryptoException{
String contentType= "text/html;charset=UTF-8";
response.setContentType(contentType);
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.setCharacterEncoding("utf-8");
String str="??????????üü";
return str;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…