-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");
3
  • 2
    When you say it doesn't work, what is the error given? Commented Apr 22, 2014 at 12:50
  • stackoverflow.com/questions/14533946/… Commented Apr 22, 2014 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 Commented Apr 22, 2014 at 13:09

1 Answer 1

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

Comments

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.