Spring MVC response encoding issue

前端 未结 4 1668
醉酒成梦
醉酒成梦 2020-12-10 21:09

In last few hours I\'ve read a lot concerning this topic, and so far nothing has worked. I\'m trying to return response containing \"odd\" some characters. Here is example o

4条回答
  •  自闭症患者
    2020-12-10 21:46

    My simple solution:

    @RequestMapping(value="test")
    public ModelAndView test(){
      String test = "čćžđš";
      ...
      ModelAndView mav = new ModelAndView("html_utf8");
      mav.addObject("responseBody", test);
    }
    

    and the view html_utf8.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>${responseBody}
    

    No additional classes and configuration.
    And You can also create another view (for example json_utf8) for other content type.

提交回复
热议问题