我试图更新表单上的几个数字值。一旦在不显示格式的情况下显示了值,我就可以轻松地将它们更改为任何数字,并将正确的数字发送到后端;然而,如果我输入了一个大的数字,例如6000000,它将在浏览器上更改为6.0E7,但是正确的数字将被发送到后端。我添加了fmt库来格式化数字,但当我提交表单时,它会将0发送到后端。
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<s:textfield id="price" name="price" value="%{price}" theme="simple"/> //6.0E7
<input name="price" id="price" value='<fmt:formatNumber value='${price}'/>'/> //0发布于 2014-04-03 10:08:48
您不需要使用JSTL的fmt,Struts2内置了格式化实用程序
然后,代替
<s:textfield name="price" value="%{price}" />
<!-- output: 6.0E7 -->例如,使用
<s:textfield name="price" value="%{getText('{0,number,#,##0.00}', {price})}" />
<!-- output: 6000000.00 -->还可以阅读有关类型转换的内容,并记住6.0E7是科学符号 (阅读更多的这里)。
发布于 2014-04-03 10:08:40
如何使用pattern属性,
<input name="price" id="price" value=
'<fmt:formatNumber value='${price}' pattern="##,####,###"/>'
/>或者type和groupingUsed之类的
<input name="price" id="price" value=
'<fmt:formatNumber value='${price}' type="number" groupingUsed="false"/>'
/>https://stackoverflow.com/questions/22828921
复制相似问题