检索在JSP中使用AJAX发送的对象数组

时间:2015-10-22 22:39:20

标签: javascript java jquery ajax jsp

关于这个问题pass array of objects to jsp,你如何在JSP中检索结果?

问题是,我在Javascript中有这个:

data = [
    {
    id: "333",
    date: "22/12/2015"
    },
    {
      id: "333",
      date: "22/12/2015"
    }]

$.post(eval.jsp, {data:data}, function(){}, "json");

如何在eval.jsp中恢复数据。我试过了

request.getParameterValues("data");

但返回的值是null。当然,这不是传递的值,如标题中所示(使用Chrome)。

1 个答案:

答案 0 :(得分:-2)

您可以使用动态表或Foreach在其中显示数据。 例如:

<table id="allStudent" class="table table-bordered">
                <thead>
                <tr>
  <th>FirstName</th>
  <th>LastName</th>
  <th>studentCode</th>
  <th>Major</th>
 <th>FatherName</th>
 <th>id</th>
  <th>Action</th>
     </tr>
        </thead>
           <tbody id="tmplBody">
            <script id="scriptTmp">

               <tr id="deleteTr" >

           <td>
                  ${firstName}

             <td>
                 ${lastName}
                 </td>
                        <td>
                            ${studentCode}
                        </td>
                        <td>
                            ${major}
                        </td>
                        <td>
                            ${fatherName}
                        </td>
                         <td>
                            ${id}
                        </td>
                        <td>

                            <button id="updateStudent" class="btn btn-success"><i class="fa fa-pencil" style="padding-right: 10px;"></i>
                                Update
                            </button>

                            <a href="#" type="button"  class="btn btn-danger deletebtn" role="button" onclick="deleteSt(${id})"><i class="fa fa-trash" style="padding-right: 10px;"></i>
                                Delete
                            </a>
                            <button  class="btn btn-info" role="button"><i class="fa fa-check" style="padding-right: 10px;"></i>Course
                                Selection
                            </button>
                        </td>
                    </tr>

                    </script>
                </tbody>


            </table>

        </div>