gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:35:20 24 4
gpt4 key购买 nike

我在练习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");

关于java - Servlet 全局化 NumberFormat.getCurrencyInstance(Locale.JAPAN) 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43251489/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com