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

Retrieving Array of Objects Sent Using AJAX in JSP

本文关键字:对象 数组 AJAX JSP 检索      更新时间:2023-09-26

关于将对象数组传递给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)。

可以使用动态表或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>