为什么控制器显示问题而不是西里尔字符?

时间:2018-10-27 12:46:33

标签: java spring http spring-mvc encoding

我无法以任何方式向服务器发送俄语字母,服务器一直在接收“ ???????”。

这是我的Spring控制器:

@RequestMapping(value = "/updateCustomerInfo", produces ="application/json;charset=UTF-8")
        @ResponseBody
        public void updateCustomerInfo(@RequestHeader(name = "id") HashMap<String,String> map){
            new CustomerManager().updateCustomerInfo(map.get("uuid"),
                    map.get("first_name"),
                    map.get("middle_name"),
                    map.get("last_name"),
                    map.get("phone"),
                    map.get("email"),
                    Boolean.parseBoolean(map.get("email_notification")),
                    map.get("adress"));
            System.out.println(map.get("first_name"));
        }

我试图在我的web.xml中添加一个过滤器,但这也无济于事:web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://java.sun.com/xml/ns/javaee"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                                http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebAppId" version="3.0"
>
    <filter>
    <filter-name>encodingFilter</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>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>controller</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>controller</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/controller-servlet.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

</web-app>

还有什么可以尝试的,请告诉我!

客户端(Android排球):

public void updateCustomerInfo(最终字符串uuid,最终字符串first_name,

最终字符串Middle_name,最终字符串last_name,最终String手机,最终

字符串电子邮件,最终布尔值email_notification,最终字符串地址){

JsonObjectRequest objectRequest =新的JsonObjectRequest(Request.Method.PUT,

http://10.0.2.2:8080/updateCustomerInfo”,空,新

Response.Listener(){

            @Override
            public void onResponse(JSONObject response) {

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }){
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String,String> map = new HashMap<>();
                map.put("Content-Type", "application/json; charset=utf-8");
                map.put("uuid",uuid);
                map.put("first_name",first_name);
                map.put("middle_name",middle_name);
                map.put("last_name",last_name);
                map.put("phone",phone);
                map.put("email",email);
                map.put("email_notification",String.valueOf(email_notification));
                map.put("adress",adress);
                return map;
            }
        };
        VolleyQueue.getInstance(context).addToRequestQueue(objectRequest);
    }

0 个答案:

没有答案