简体   繁体   English

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

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

I came across the following issue when I have been practicing on Java Servlet globalization: 在从事Java Servlet全球化练习时,遇到了以下问题:

NumberFormat.getCurrencyInstance(Locale.UK) NumberFormat.getCurrencyInstance(Locale.UK)

is working perfectly while 在完美的同时

NumberFormat.getCurrencyInstance(Locale.JAPAN) NumberFormat.getCurrencyInstance(Locale.JAPAN)

is showing '?' 显示“?” instead of '‎¥'. 而不是“¥”。

Here is my code: 这是我的代码:

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>");
    }

Output on Google Chrome: 在Google Chrome上的输出:

Format currency with UK locale: £5,000,000.00 在英国区域设置格式货币:£5,000,000.00

Currency Format using Japan Locale: ?5,000,000 使用日本语言环境的货币格式:?5,000,000

Please help me out to solve the problem. 请帮我解决问题。 Thank you! 谢谢!

try instead of response.setContentType("text/html"); 尝试代替response.setContentType(“ text / html”); response.setContentType("text/html; charset=utf-8"); response.setContentType(“ text / html; charset = utf-8”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 NumberFormat.getCurrencyInstance(Locale.US) 转换为 Double - How to convert NumberFormat.getCurrencyInstance(Locale.US) to Double 修改NumberFormat.getCurrencyInstance()返回的NumberFormat - Modifying the NumberFormat returned by NumberFormat.getCurrencyInstance() NumberFormat.getCurrencyInstance()将所有内容都归零? - NumberFormat.getCurrencyInstance() turning everything to zero? Java:获取NumberFormat.getCurrencyInstance()结果的不同部分 - java: get different parts of NumberFormat.getCurrencyInstance() result NumberFormat.getCurrencyInstance()的Currency格式基于什么标准? - What standard is the Currency formatting of NumberFormat.getCurrencyInstance() based on? NumberFormat.getCurrencyInstance() 不返回语言环境中国和法国的货币符号 (jdk-1.8) - NumberFormat.getCurrencyInstance() not returning currency symbol for Locales CHINA and FRANCE (jdk-1.8) 为什么此for循环不起作用? - Why doen't this for loop work? RequestDispatcher:Servlet映射无法正常工作 - RequestDispatcher: Servlet mapping doesn't work properly getCurrencyInstance(new Locale("fr", "FR")) 和 getCurrencyInstance(Locale.FRANCE) 之间的区别 - difference between getCurrencyInstance(new Locale("fr", "FR")) and getCurrencyInstance(Locale.FRANCE) 默认语言环境和数字格式 - default locale and numberformat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM