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).

3
  • 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 stackoverflow.com/questions/14217790/… It is interesting what wonders a little bit of googling can do. Commented Oct 22, 2015 at 22:51
  • same way you do if it is a form, default content type is form encoded Commented Oct 22, 2015 at 23:44
  • Sounds like you might need a JSON library for Java Commented Oct 23, 2015 at 0:38

1 Answer 1

-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>
Sign up to request clarification or add additional context in comments.

1 Comment

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..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.