2015-04-07 47 views
0

我有一個jsp頁面。在jsp頁面中,我有一些對象說歷史。在jquery中,我得到了index.Now我想將歷史[index]對象傳遞給struts2中的action類。這是我嘗試過的代碼,但它顯示錯誤。在struts2中傳遞數組對象到動作類

$(document).ready(function() { 
$(function() { 
    var rateDialog = $("#rateDialog").dialog({ 
     autoOpen: false, 
     minHeight:250, 
      width: 400, 
      height: 265, 
     open: function(event, ui) { 
      $("#showDialogMessage").hide(); 
      $('#reviewArea').val(''); 
      } 
     }); 

     $(".rate").on("click", function() { 
      // Display the dialog 
      rateDialog.dialog("open"); 
      alert($(this).attr("id")); 
      var index = $(this).attr("id"); 
      alert("${history.get(index)}"); 
     }); 
}); 
$("#submit").click(function(e) { 
$("#showDialogMessage").hide(); 
    var xmlhttp; 
    $("#submit").prop('disabled',true); 
    alert("called"); 
     var url="rate?object="+${history.get(index)}; 
     if (window.XMLHttpRequest) 
     { 
      xmlhttp=new XMLHttpRequest(); 
     } 
     else 
     { 
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
     } 
     xmlhttp.onreadystatechange=function() 
     { 

      if (xmlhttp.readyState==4 && xmlhttp.status==200) 
      { 
       $("#submit").removeAttr('disabled'); 
       document.getElementById("showPasswordMessage").innerHTML=xmlhttp.responseText; 
       $("#showPasswordMessage").show(); 
      } 
     } 

     xmlhttp.open("GET", url, true); 
     xmlhttp.send(); 
}); 
}); 
+0

什麼是錯誤?它在瀏覽器或服務器端嗎? – ramp

+0

這是錯誤SyntaxError:非法字符 \t rl =「rate?object =」+ [email protected]; –

+0

這個錯誤在哪裏?瀏覽器還是服務器?用完整的信息更新您的問題。 – Chaitanya

回答

1
var url="rate?object="+${history.get(index)}; 

這不是Java的問題,這是JavaScript的。 上面一行是罪魁禍首

${history.get(index)} 

是在服務器上執行的JSP代碼和它提取一個對象。打印的是對象的toString()表示形式([email protected])。你可能應該訪問對象的屬性

${history.get(index).someProperty} 
+0

我試過了。在動作類中,它給出null。這裏是我的代碼var url =「rate?index =」+ index +「&rating =」+ rating +「&review =」+ review +「&transactionId」+ $ {history.get(index).transactionId};並在action類中爲getId和setter設置transactionId –