非英语字符显示?在Action类中

时间:2016-02-29 08:59:45

标签: jsp tomcat utf-8 configuration character-encoding

我使用jquery ajax提交以下表单,我在Action类方法中打印值。我正在使用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>

行动中

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"/>

在Jsp Page

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

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

我正在获得输出

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

??是印地文字符

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您也需要在 UTF-8 IDE下运行,以便在控制台中正确显示输出。

在Eclipse中:

enter image description here

source

在NetBeans中:

enter image description here

然后,请注意 NetBeans使用无法重现所有UTF-8字符的字体,然后您需要按如下方式更改它:

enter image description here

enter image description here

source