2

When I run JSP page with RequsetDispatcher it shows me the cyrillic content with "????...".

RequestDispatcher view = request.getRequestDispatcher("/view.jsp");

Here is what I tried:

I am using Apache Tomcat and I added that in the VM-options:

-Dfile.encoding=UTF-8

In the beginning of the jsp file:

<%@page contentType="text/html" pageEncoding="UTF-8"%>

In web.xml:

<jsp-config>
        <jsp-property-group>
            <url-pattern>*.jsp</url-pattern>
            <page-encoding>utf-8</page-encoding>
        </jsp-property-group>
    </jsp-config>

    <filter> 
        <filter-name>CharSet</filter-name> 
        <filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class> 
        <init-param> 
            <param-name>encoding</param-name> 
            <param-value>utf-8</param-value> 
        </init-param> 
    </filter> 

    <filter-mapping>
        <filter-name>CharSet</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>  

In the connectors in tomcat configuration file conf/server.xml:

 URIEncoding="UTF-8" 

And it still doesn't work. Any ideas how to fix it?

Edit: Fixed when I aded response.setCharacterEncoding("UTF-8"); in the Servlet method.

f_puras
  • 2,521
  • 4
  • 33
  • 38
Freak0345
  • 47
  • 8

2 Answers2

1

It seems that your problem is most probably related to the application server you are using.

Please refer to this thread and try to solve your problem by changing your application-server configuration file to use UTF-8 -> How to get UTF-8 working in Java webapps

Mehdi
  • 3,795
  • 3
  • 36
  • 65
0

The missing piece was adding response.setCharacterEncoding("UTF-8"); in the beginning of the dopost method in the Servlet.

Freak0345
  • 47
  • 8