Shubham Chopra
Shubham Chopra

Reputation: 1737

Russian Characters are appearing as ??? in Spring-MVC

So I have created a controller

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

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

Now when i hit the url http://localhost:8080/SpringMVC/hello/all I am getting ??????? ???? in the response.

I have configured URIEncoding in server.xml file of tomcat something like this

<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"/>

I have tested my response on Chrome browser,postman and eclipse console.

I have even tried adding encoding-filter in web.xml file

<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>

Please help me what am i missing?

Upvotes: 4

Views: 1828

Answers (2)

LppEdd
LppEdd

Reputation: 21172

Might be that you need to define the encoding of the response body.
For that you can use the @RequestMapping annotation, e.g.

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

Upvotes: 1

Julien Aubin
Julien Aubin

Reputation: 36

Did you define the source encoding while building your project ?

Upvotes: 0

Related Questions