Spring MVC Character Encoding

I'm having problems with Turkish characters ... There are no problems on my JSP pages ... but when a warning appears on the Java side, the Turkish character (ŞşİığĞüÜç ...) looks like (Ä ±,?, ü, §, Å , ...)

In JSP pages I use this code, and ı can solve the Turkish character problem

<%@ page contentType="text/html;charset=UTF-8" language="java"%>

in Spring MVC configuration, I tried a lot, but I didn’t succeed ... For example, in my mvc configuration class I set my MessageSource as follows:

@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasename("classpath:messages");
    messageSource.setUseCodeAsDefaultMessage(true);
    messageSource.setDefaultEncoding("UTF-8");
    messageSource.setCacheSeconds(0);
    return messageSource;
}

In this program, I try to enter a reset password, and I dialed an unregistered email address. Finally, I get an exception, and this is the following code for the blog code.

@Autowired
private MessageSource messages;
...

@ExceptionHandler({ UserNotFoundException.class })
public ResponseEntity<Object> handleUserNotFound(final RuntimeException exception, final WebRequest request) {
    logger.error("404 Status Code", exception);
    final GenericResponse bodyOfResponse = new GenericResponse(messages.getMessage("message.userNotFound", null, request.getLocale()), "UserNotFound");
    return handleExceptionInternal(exception, bodyOfResponse, new HttpHeaders(), HttpStatus.NOT_FOUND, request);
}

In the messages_tr_TR.properties file

...
message.userNotFound=Kullanıcı Bulunamadı
...

but on JSP pages this warning is displayed like this:

KullanÄ ± cÄ ± BulunamadÄ ±

How can I solve this problem.

+4
2

, . , json,

HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add("Content-Type", "application/json; charset=utf-8");
return handleExceptionInternal(exception, responseHeaders, HttpStatus.NOT_FOUND, request);
+1

web.xml:

<jsp-config>
    <!-- global JSP configuration -->
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
</jsp-config>

<filter>
    <filter-name>characterEncodingFilter</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>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

(). ? UTF-8? , , JSON ...

+1

Source: https://habr.com/ru/post/1584201/


All Articles