俄罗斯人物出现在???在Spring-MVC中

问题描述 投票:0回答:2

所以我创建了一个控制器

@Controller
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping("/all")
    @ResponseBody
    public String display()
    {
        return "Мегафон Игры";  //russian characters
    }   
}

现在当我点击网址http://localhost:8080/SpringMVC/hello/all时,我在回复中得到了??????? ????

我已经在tomcat的server.xml文件中配置了URIEncoding

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>` 
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>

我已经在Chrome浏览器,邮递员和eclipse控制台上测试了我的回复。

我甚至尝试在web.xml文件中添加encoding-filter

<filter>
    <filter-name>encoding-filter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
       <param-name>encoding</param-name>
       <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
       <param-name>forceEncoding</param-name>
       <param-value>FALSE</param-value>
    </init-param>
 </filter>
 <filter-mapping>
    <filter-name>encoding-filter</filter-name>
    <url-pattern>/*</url-pattern>
 </filter-mapping>

请帮帮我,我错过了什么?

java spring-mvc tomcat servlets utf-8
2个回答
1
投票

可能是您需要定义响应主体的编码。 为此,您可以使用@RequestMapping注释,例如

@RequestMapping(
     value = "/all", 
     method = RequestMethod.GET,
     produces = MediaType.APPLICATION_JSON_UTF8_VALUE
)

0
投票

您是否在构建项目时定义了源代码?

© www.soinside.com 2019 - 2024. All rights reserved.