首页 > 解决方案 > 为什么控制器显示问题而不是西里尔字符?

问题描述

我无法以任何方式向服务器发送俄语信件,服务器不断收到“???????”。

这是我的 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(final String uuid, final String first_name,

final String middle_name, final String last_name, final String phone, final

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

JsonObjectRequest objectRequest = new 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);
    }

标签: javaspringhttpspring-mvcencoding

解决方案


推荐阅读