Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Struts2:包含字符串和双精度值的映射返回双精度值的null_Java_Javascript_Jquery_Ajax_Struts2 - Fatal编程技术网

Java Struts2:包含字符串和双精度值的映射返回双精度值的null

Java Struts2:包含字符串和双精度值的映射返回双精度值的null,java,javascript,jquery,ajax,struts2,Java,Javascript,Jquery,Ajax,Struts2,我想知道如何将包含字符串和双值的HashMap从Action传递到javascript代码 当我编辑一些具有双值的字段时,这些字段上有一个空值,我如何解决这个问题 行动: public String query() { Service = new ServiceImpl(); v = new Vehicule(); v= Service.getByImmat(im); map.put("kilo", v.getKilo()); //double value

我想知道如何将包含字符串和双值的
HashMap
从Action传递到javascript代码

当我编辑一些具有双值的字段时,这些字段上有一个空值,我如何解决这个问题

行动:

 public String query() {
    Service = new ServiceImpl();
    v = new Vehicule();
    v= Service.getByImmat(im);
    map.put("kilo", v.getKilo()); //double value
    /*SimpleDateFormat formatter5=new SimpleDateFormat("yyyy-MM-dd");
    String formats1 = formatter5.format(ss1);*/
    map.put("datepicker", formats1);
    map.put("etat", v.getEtat());//string value
    map.put("capacite_bagages", v.getCapacite_bagage()); //double value
    return "success";
}
<script type="text/javascript">
$(document).ready(function() 
    {

      $('#imm').change(function()
        {


          var selectedValue = $('#imm').val();
            if ($.trim(selectedValue).length > 0) 
             {
                $.ajax(
                {
                    type: 'POST', 
                    url  : "<s:url action='query'/>",
                    dataType : 'json',
                    data: { imm : selectedValue},
                    success: function(result){                                                                                     
                        $.each(result, function(key,value)
                        {                    


                                $("#"+key).val(value);

                                                            } );                                
    });
</script>

<s:form  cssStyle="border:0;" validate="true" action="modifiervehicule" namespace="/" >
<s:select  id="imm" label="immatriculation" list="immatriculs" name="immatricul"></s:select>
<s:textfield id="kilo"  name="kil" label="kilometrage" size="15" ></s:textfield>
<s:textfield  id="etat" name="etat" label="etat" size="15" ></s:textfield>
 <s:textfield  id="datepicker" name="date" label="date"  size="15" ></s:textfield> 
<s:textfield id="capacite_bagages" name="capacite_bagages" label="capacité de bagages" size="15"></s:textfield>

<s:submit  style="height:30px; width:125px" name="Valider" value="Valider"></s:submit>
</s:form>
阿贾克斯:

$.ajax({
    type: 'POST', 
    url  : "<s:url action='query'/>",
    dataType : 'json',
    data: { imm : selectedValue},
    success: function(result) {
        $.each(result, function(key,value){ 
            $("#"+key).val(value); 
        });
    });
我在我的jsp中显示它,我在我的jsp页面中编辑它,但是当我想保存结果时,双值取NAN!!:

public String modifiervehicule () {

        Service = new ServiceImpl();
        v= new Vehicule();
        v = vehiculeService.getVehiculeByImmat(immatricul);
        v.setKilo((Double)getKilo());
        v.setDate((Date)getDate());
        v.setEtat(getEtat());
        v.setCapacite_bagage((Double)getCapacite_bagages());

        v = Service.update(v);
        return "success";

    }
基洛字段(双精度)在编辑后有一个空值,但如果我用整数值编辑它,它将不会有空值

我想是因为
public double getkilo()
应该返回我在映射中传递的double not对象!!)

编辑2:

 public String query() {
    Service = new ServiceImpl();
    v = new Vehicule();
    v= Service.getByImmat(im);
    map.put("kilo", v.getKilo()); //double value
    /*SimpleDateFormat formatter5=new SimpleDateFormat("yyyy-MM-dd");
    String formats1 = formatter5.format(ss1);*/
    map.put("datepicker", formats1);
    map.put("etat", v.getEtat());//string value
    map.put("capacite_bagages", v.getCapacite_bagage()); //double value
    return "success";
}
<script type="text/javascript">
$(document).ready(function() 
    {

      $('#imm').change(function()
        {


          var selectedValue = $('#imm').val();
            if ($.trim(selectedValue).length > 0) 
             {
                $.ajax(
                {
                    type: 'POST', 
                    url  : "<s:url action='query'/>",
                    dataType : 'json',
                    data: { imm : selectedValue},
                    success: function(result){                                                                                     
                        $.each(result, function(key,value)
                        {                    


                                $("#"+key).val(value);

                                                            } );                                
    });
</script>

<s:form  cssStyle="border:0;" validate="true" action="modifiervehicule" namespace="/" >
<s:select  id="imm" label="immatriculation" list="immatriculs" name="immatricul"></s:select>
<s:textfield id="kilo"  name="kil" label="kilometrage" size="15" ></s:textfield>
<s:textfield  id="etat" name="etat" label="etat" size="15" ></s:textfield>
 <s:textfield  id="datepicker" name="date" label="date"  size="15" ></s:textfield> 
<s:textfield id="capacite_bagages" name="capacite_bagages" label="capacité de bagages" size="15"></s:textfield>

<s:submit  style="height:30px; width:125px" name="Valider" value="Valider"></s:submit>
</s:form>
jsp:

 public String query() {
    Service = new ServiceImpl();
    v = new Vehicule();
    v= Service.getByImmat(im);
    map.put("kilo", v.getKilo()); //double value
    /*SimpleDateFormat formatter5=new SimpleDateFormat("yyyy-MM-dd");
    String formats1 = formatter5.format(ss1);*/
    map.put("datepicker", formats1);
    map.put("etat", v.getEtat());//string value
    map.put("capacite_bagages", v.getCapacite_bagage()); //double value
    return "success";
}
<script type="text/javascript">
$(document).ready(function() 
    {

      $('#imm').change(function()
        {


          var selectedValue = $('#imm').val();
            if ($.trim(selectedValue).length > 0) 
             {
                $.ajax(
                {
                    type: 'POST', 
                    url  : "<s:url action='query'/>",
                    dataType : 'json',
                    data: { imm : selectedValue},
                    success: function(result){                                                                                     
                        $.each(result, function(key,value)
                        {                    


                                $("#"+key).val(value);

                                                            } );                                
    });
</script>

<s:form  cssStyle="border:0;" validate="true" action="modifiervehicule" namespace="/" >
<s:select  id="imm" label="immatriculation" list="immatriculs" name="immatricul"></s:select>
<s:textfield id="kilo"  name="kil" label="kilometrage" size="15" ></s:textfield>
<s:textfield  id="etat" name="etat" label="etat" size="15" ></s:textfield>
 <s:textfield  id="datepicker" name="date" label="date"  size="15" ></s:textfield> 
<s:textfield id="capacite_bagages" name="capacite_bagages" label="capacité de bagages" size="15"></s:textfield>

<s:submit  style="height:30px; width:125px" name="Valider" value="Valider"></s:submit>
</s:form>

使
映射
映射对象而不是字符串。比如说

Map<String, Object> map= new HashMap<>();
Map Map=newhashmap();
现在必须将对象放入其中,如果值为
null
,它将保留
success
处理程序返回JSON结果后可以获得的值。另见
.

您的代码缺少一些片段(Service=,等等)。什么是地图?双变量有哪个值?第页打印的是什么?私人服务;//使用hibernate private Map Map=new HashMap()连接到数据库的服务;我仍然有一个空值!我想更新一些值(string、Integer和double),因为这个原因,我将这些参数传递到从action到jsp页面的映射中。我在我的jsp中显示它,我编辑它,但是当我想保存结果时,所有的双精度值都是NAN!!我不明白你在说什么,你能更新你的问题吗?我不知道动作是如何映射到JSP的,所以发布
struts.xml
。还可以使用缩进对代码进行格式化