0

With respect to this question pass array of objects to jsp, how do you retrieve the results in JSP?

The question is, I have this in my Javascript:

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

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

How do i recover data in eval.jsp. I tried

request.getParameterValues("data");

But the value returned is null. This is not the value passed of course as can be seen in the headers (using Chrome).

Community
  • 1
  • 1
osbon123
  • 499
  • 3
  • 11
  • using a for each loop like you do in java. JSP allows embedding java code as well as javascript. In your case it will be a loop processed in javascript. Have a look at this http://stackoverflow.com/questions/14217790/accessing-objects-in-json-array-javascript It is interesting what wonders a little bit of googling can do. – Acewin Oct 22 '15 at 22:51
  • same way you do if it is a form, default content type is form encoded – charlietfl Oct 22 '15 at 23:44
  • Sounds like you might need a [JSON library for Java](https://www.google.com/search?q=JSON+library+for+Java&ie=utf-8&oe=utf-8) – James Oct 23 '15 at 00:38

1 Answers1

-2

You can use a dynamic table or Foreach to show data in it . Example:

<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>
reihane
  • 39
  • 7
  • I think you have misunderstood the question. It is asking how to retrieve the data sent to jsp in the jsp itself. your answer is about showing a collection in the client side. Also your code doesnt have any loop so i am not exactly sure how it will iterate.. – suvartheec Jun 12 '18 at 06:11