[英]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.