小编ysn*_*nky的帖子

Spring MVC中的UTF-8编码问题

我有一个Spring MVC bean,我想通过设置UTF-8编码来恢复土耳其语.但是虽然我的字符串是"şŞğĞİıçÇöÖüÜ"但它返回"??????çÇöÖüÜ".而且当我查看响应页面,即Internet Explorer页面时,编码是西欧iso,而不是UTF-8.

这是代码:

    @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;
}   
Run Code Online (Sandbox Code Playgroud)

java spring-mvc utf-8 character-encoding

48
推荐指数
5
解决办法
12万
查看次数

标签 统计

character-encoding ×1

java ×1

spring-mvc ×1

utf-8 ×1