Struts 2:带点或逗号的双精度值 [英] Struts 2 : double values with point or comma
问题描述
我不能用点插入双精度值的问题(示例2.2),但是我可以用逗号插入双精度值(示例:2,2).
The problem that I can't insert double values with point (example 2.2), however I can insert them with comma (example : 2,2).
但是当我想使用(JSP和Ajax)编辑它们时,即使我用逗号存储它们,它们也带有(点)出现,所以我必须编辑所有值!
but when I want to edit them using (JSP and Ajax), they appear with (point) even if I stock them with comma, so that I have to edit all values !
场景如下:我想在我的应用程序中编辑一些double值(hibernate和struts2),我将这些值从action传递给JSP:
the scenario is as follows : I want to edit some double values in my application (hibernate and struts2),i pass the values from action to JSP :
private Service Service;
private Vehicule v;
private Map<String, Object> map= new HashMap<>();
public String query()
{
Service = new ServiceImpl();
v = new Vehicule();
v= Service.getVehiculeByImmat(field1);
map.put("date", v.getdate().toString());
map.put("kilometrage", v.getKilometrage());
return "success";
}
然后将它们显示在我的JSP中:
$(document).ready(function(){
$('#field1').change(function(){
var selectedValue = $('#field1').val();
if ($.trim(selectedValue).length > 0)
{
alert(selectedValue);
$.ajax(
{
type: 'POST',
url : "<s:url action='query'/>",
dataType : 'json',
data: { field1: selectedValue},
success: function(result){
$.each(result, function(key,value)
{ $("#"+key).val(value);
} );
},
});
}
}
);
});
struts.xml
:
struts.xml
:
<action name="query" class="action.GestionVehicules" method="query">
<result name="success" type="json">map</result>
</action>
我的问题:是否可以将double值插入point?
my question : it's possible to insert the double values with point ?
推荐答案
默认语言环境与客户端上的预期语言环境不同.对于这些语言环境,分数数字格式也有所不同.您可以将操作区域设置为美国区域设置,以在序列化为JSON时使用它.根据该语言环境,它使用小数点分隔小数点,并使用逗号进行分组.
The default locale is different than expected on the client side. Fractional numbers format is also different for those locales. You could set a US locale to the action context to use it when serialized to JSON. According to this locale it uses a dot for fractional part separator and comma for grouping.
ActionContext.getContext().setLocale(Locale.US);
在返回结果之前执行此操作.
Do it before returning a result.
这篇关于Struts 2:带点或逗号的双精度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!