Freak0345
Freak0345

Reputation: 47

JSP doesn't display cyrillic content?

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.

Upvotes: 2

Views: 681

Answers (2)

Freak0345
Freak0345

Reputation: 47

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

Upvotes: 0

Mehdi
Mehdi

Reputation: 3763

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

Upvotes: 1

Related Questions