4

I am having trouble with Turkish characters...In my JSP pages, there is no problem... but, when an alert come from Java side, Turkish character(ŞşİığĞüÜç...) seems like that (ı,?,ü,ç,Å,...)

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

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

in Spring MVC config, I tried a lot of way but I didn't succeed... For example In my mvc config class, I set my MessageSource like that;

@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 reset password and I typed unregister email address..Finally I am getting exception and this following is exception code blog.

@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 my messages_tr_TR.properties file,

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

but In JSP pages this alert shows like that;

Kullanıcı Bulunamadı

How can I solve this problem..

3
  • With encoding there are several common causes, you can try adding the filter and configuring your servlet container as suggested here. Here you can find a comprehensive list of common issues, check the point number two if the first link doesn't help Commented Apr 23, 2015 at 9:03
  • Hi @MasterSlave ,thanks for comment. I've tried second link before...In first link, there are a lot of ways but I am looking for Spring MVC one...How can I solve this issue in Spring MVC Commented Apr 23, 2015 at 9:44
  • I've added an answer simply on account of formatting, but in reality its only yet another suggestion, let me know if it helped Commented Apr 23, 2015 at 9:52

2 Answers 2

1

Comment follow-up, you can set the encoding in your response header as well. An example if you're returning json would be

HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add("Content-Type", "application/json; charset=utf-8");
return handleExceptionInternal(exception, responseHeaders, HttpStatus.NOT_FOUND, request);
Sign up to request clarification or add additional context in comments.

1 Comment

I tried but it didn't work :( I am getting same result.
1

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

Put the actual text in the handler method (temporarily). Does it now look right? Is your messages file correctly saved as UTF-8? Also, I can't tell if you're using JSON or not...

2 Comments

thanks for answer but it didn't work...when I add this to the web.xml, it effects only some information messages...I mean, there is no neccessary to use this code blog in jsp pages anymore <%@ page contentType="text/html;charset=UTF-8" language="java"%> .... As I understand message.userNotFound=Kullanıcı Bulunamadı message use different way... I am having trouble only some information messages not all of them.
By the way, I didn't understand very well "Is your messages file correctly saved as UTF-8?" what did you mean???

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.