我对 jstl 标签库感到困惑:
我想将数字格式化为德国风格的货币...但我尝试的一切都不起作用...
我找到了以下示例,但输出是相同的 -.-
<%@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
那里出了什么问题?
感谢您的帮助。
太棒了,偶然我得到了我的问题的解决方案:
技巧是设置范围参数setLocale
标记到会话 :D 然后它就可以工作了 ^^ 甜蜜的:)
所以正确的代码片段如下:
<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"/>
好吧,我真的不知道它为什么有效,但这里有一些有关我的项目设置的更多信息:
- Spring 3 框架(MVC、安全性)
- 以及标准应用程序和 servlet 设置
- 所有东西都在 tomcat 7 中运行,所以我使用 JSP 2.2
希望能帮助到你。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)