Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

111
Views
how to get the array in servlet which passed from ajax call

I am passing an array from servlet through ajax call. But when I am trying to get the same in servlet side, I am getting null pointer exception. I tried using one of the examples given in SO. Since I'm a newbie, any help would be appreciated!

$.ajax({
				url : 'insertserv1',
				type: 'POST',
				dataType: 'json',
				data: {tablearray:tablearray} ,
		        contentType: 'application/json',
		        mimeType: 'application/json',
				success : function(data) {
							alert('Hi');
						}			
		    });

// to get data from inspection table
		{ var tablearray = [];
			$("#tab_logic tr.data").map(function (index, tr) {
            $(this).find('td').each(function(){
                var $data = $(this).html();
                	if($(this).find("select").length > 0) {
                        var $x = $(this).find("select").val();
                    }else{
 	                	var $x = $(this).find("input[type='text']").val();
 	             	}
                	tablearray.push($x);
            });  	
         });
		}

String[] tablearray = request.getParameterValues("tablearray[]");
		
for (int i = 0; i < tablearray.length; i++) {
  System.out.println(InspTableArray[i]);
}

8 months ago · Santiago Trujillo
1 answers
Answer question

0

If I have understood correctly, this is what you would be looking for:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
    JSONObject jObj = null;
    StringBuilder sb = new StringBuilder();
    BufferedReader br = request.getReader();
    String str = null;
    while ((str = br.readLine()) != null)
    {
        sb.append(str);
    }
    try
    {
        jObj = new JSONObject(sb.toString()); //This is your JSON data.
    }
    catch (JSONException e)
    {
        e.printStackTrace();
    }
}
8 months ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.