1. What is printed in console in first for loop?
2. What is printed in console in second for loop?
3. Request.getAttribute(
String val) should not be used in case of Ajax call.
Scriplets are discredited since some 15 years. Avoid them.
Use JQuery and JSON for ajax calls, it will make your life way too simple.