xrcwrn
xrcwrn

Reputation: 5327

Non english characters are showing ?? in Action class

I am submitting following form using jquery ajax and I am printing the values in Action class method. I am using tomcat 7

<form action="PostNow" id="post_now">
     <s:textarea name="message" style="width:100%;height:80px" 
                   id="text_message" cssClass="form-control" placeholder="Post now">
     </s:textarea>
</form>

In action

public String insert() {
    HttpServletRequest request = ServletActionContext.getRequest();
    System.out.println("char en "+request.getCharacterEncoding());
    System.out.println("sendor " + message());
}

Web.xml

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" URIEncoding="UTF-8"/>

In Jsp Page

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

In web.xml

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

I am getting output

char en UTF-8
?????? ????? ????? ?? ?????? ?? ???? 

?? are hindi characters

How to resolve this ?

Upvotes: 1

Views: 125

Answers (1)

Andrea Ligios
Andrea Ligios

Reputation: 50281

You need to run under UTF-8 your IDE too, to have the output correctly shown in the console.


In Eclipse:

enter image description here

(source)


In NetBeans:

enter image description here

Then, be aware that NetBeans uses a Font not able to reproduce all the UTF-8 characters, then you need to change it as follows:

enter image description here

enter image description here

(source)

Upvotes: 1

Related Questions