-1

My problem is as follow: I am making an AJAX call to a jsp and from their am getting a JSON Object comprising of a flag and an ArrayList

JSP:

Gson gson = new Gson();
JsonObject root = new JsonObject();
root.addProperty("flag", flag); //add flag
root.addProperty("list", gson.toJson(list)); 
out.println(gson.toJson(root));

Now in the success function of my AJAX function I want to move to some other jsp so I did something like this:

success: function(response){
alert(JSON.stringify(response.list));
//alert(JSON.stringify(response.flag));
if(JSON.stringify(response.flag).indexOf("true")>=0){
    location.href="GroupLoginScreen.jsp";  
}
else{
    alert("UNSUCCESSFUL");
}
}

Now, The problem part is though am getting the results here correct But how to send this list as an argument in URL with GroupLoginScreen.jsp so that at receiving end it can be obtained by just doing something like this:

ArrayList<String> list1 = (ArrayList<String>)request.getAttribute("mylist");
Zoe
  • 27,060
  • 21
  • 118
  • 148
user3522121
  • 215
  • 3
  • 10
  • 23
  • 2
    When you say it doesn't work, what is the error given? – Rory McCrossan Apr 22 '14 at 12:50
  • http://stackoverflow.com/questions/14533946/pass-a-javascript-object-to-a-jsp-page-using-jquery – Tuhin Apr 22 '14 at 12:54
  • @RoryMcCrossan Iam not able to move to next page though the alert(response.flag); alert(response.list);provide right results.Also i dont know how to pass this list along with the url as a parameter to next page and how to get it at recieving end – user3522121 Apr 22 '14 at 13:09

1 Answers1

0

location.href="GroupLoginScreen.jsp" will make new GET request from the browser so in GroupLoginScreen.jsp, you can't get 'mylist' attribute like you did.

The solution for you is you have to encode your list into a String using encodeURIComponent function then add 'mylist' as query parameter into GroupLoginScreen.jsp.

The code something like this:

var mylistParam = encodeURIComponent ( json_text_of_the_list );

location.href = "GroupLoginScreen.jsp?mylist=" + mylistParam;  

In GroupLoginScreen.jsp.

String myList = request.getParameter("mylist");

Convert myList as String into ArrayList
LHA
  • 9,398
  • 8
  • 46
  • 85