Servlet 全球化 NumberFormat.getCurrencyInstance(Locale.JAPAN) 无法正常工作

Servlet Globalization NumberFormat.getCurrencyInstance(Locale.JAPAN) doen't work properly

我在练习Java Servlet 全球化时遇到了以下问题:

NumberFormat.getCurrencyInstance(Locale.UK)

期间运行良好

NumberFormat.getCurrencyInstance(Locale.JAPAN)

显示“?”而不是“ ¥”。

这是我的代码:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        out.println("<html>");
        out.println("<head>");
        out.println("<title>Detecting Locale </title>");
        out.println("</head>");
        out.println("<body>");

        long number = 5_000_000L;

        NumberFormat numForUK = NumberFormat.getCurrencyInstance(Locale.UK);
        out.println("<p>Format currency with UK locale: " + numForUK.format(number) + "</p>");

        NumberFormat numForJAPAN = NumberFormat.getCurrencyInstance(Locale.JAPAN);
        out.println("<p>Currency Format using Japan Locale: " + numForJAPAN.format(number));

        out.println("</body>");
        out.println("</html>");
    }

Google 上的输出 Chrome:

Format currency with UK locale: £5,000,000.00

Currency Format using Japan Locale: ?5,000,000

请帮我解决问题。 谢谢!

尝试代替 response.setContentType("text/html"); response.setContentType("text/html; charset=utf-8");