0

I am in need of your help.

I have this array being passed from Javascript to Java Servlet using AJAX.

Javascript and AJAX snippet code:

var BuildingNo = [];

$(xml).find('BUILDING').each(function(){
    BuildingNo.push($.trim(this).children('BuildingNo').text());
}

The value of BuildingNo before passing to Java Servlet.

alert(BuildingNo);
// 00101,00102,00103,00104,00105 

The value of JSON.stringify(BuildingNo) when I passed the BuildingNo through Ajax to Java Servlet.

data: { BuildingNo : JSON.stringify(BuildingNo) },

alert(JSON.stringify(BuildingNo));
// ["00101","00102","00103","00104","00105"] 

Here is the Java Servlet snippet code I am using to pass the BuildingNo to oldBuilding list.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws (ServletException, IOException {

List <String> oldBuildingList = Arrays.asList(request.getParameter("BuildingNo");

logger.info(oldBuildingList);

// [["00101","00102","00103","00104","00105"]] -- This is a wrong format.

//I have a Java code here which captures a new list of BuildingNo from another service.

List <String> newBuildingList = new ArrayList <String>();
logger.info(newBuildingList.toString());

// [00106,00107,00108,00109,00110] -- This should be the correct format of oldBuildingList.

}

How do I get the same format of newBuildingList using oldBuildingList?

1 Answer 1

1

Don't stringify just keep as data: { BuildingNo : BuildingNo }

and in Java Servlet List <String> oldBuildingList = Arrays.asList(request.getParameterValues("BuildingNo[]");

Sign up to request clarification or add additional context in comments.

1 Comment

Your are welcome. Happy to hear that @Ragome Cheers !!

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.