SetLocale在JSP网站中无法使用德语设置货币格式 [英] SetLocale did not work in jsp site to format currency in german

查看:107
本文介绍了SetLocale在JSP网站中无法使用德语设置货币格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对jstl标签库感到困惑:

I'm confused with the jstl tag libs:

我想将数字格式化为德国风格的货币...但是我尝试的所有方法都无效...

I want to format a number to a currency with german style ... but everything I tried did not worked ...

我找到了以下示例,但输出是相同的-.-

I found the following example but the output is the same -.-

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core"
      prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt"
      prefix="fmt" %>

<html>
<head>
    <title>format number</title>
</head>
<body>
    <c:set var="val" value="40.52" />
    <p> Currency in USA
    <fmt:setLocale value="en_US"/>
    <fmt:formatNumber value="${val}"
              type="currency" />
    </p>

    <p>Currency in Germany
    <fmt:setLocale value="de_DE"/>
    <fmt:formatNumber value="${val}"
              type="currency"/>
    </p>
</body>
</html>

多数民众赞成在输出:

Currency in USA $40.52

Currency in Germany $40.52

那里出了什么问题?

感谢您的帮助.

推荐答案

太棒了,偶然地我得到了解决问题的方法:

Awesome, by chance I got the solution to my problem:

技巧是将setLocale标记的作用域参数设置为session:D,然后起作用^^ sweet:)

The trick is to set the scope-parameter of the setLocale tag to session :D and then it works ^^ sweet :)

因此正确的代码段如下所示:

So the correct code snippet looks like:

<c:set var="val" value="40.52" />
<p> Currency in USA
<fmt:setLocale value="en_US" scope="session"/>
<fmt:formatNumber value="${val}"
          type="currency" />
</p>

<p>Currency in Germany
<fmt:setLocale value="de_DE" scope="session"/>
<fmt:formatNumber value="${val}"
          type="currency"/>

好吧,我真的不知道为什么会这样,但是这里有一些有关我的项目设置的更多信息:

Ok, I do not really know why it works, but here is some more information about my project setup:

  • Spring 3框架(MVC,安全性)
  • 以及标准应用程序和servlet设置
  • 每件事都在tomcat 7中运行,所以我使用JSP 2.2

希望有帮助.

这篇关于SetLocale在JSP网站中无法使用德语设置货币格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆