0

Following code for my output:

    PrintWriter out = response.getWriter();     


    ObjectMapper objectMapper = new ObjectMapper();
    ToJson obj = new ToJson();
    String obj1 = objectMapper.writeValueAsString(obj);
    response.setContentType("application/json");

    out.print(obj1);

    System.out.println(obj1);

    out.close();

The obj1 looks like this: {"prname1":"P1neu","anz1":"342356","prid1":"1","price1":"25"}

It should send the string out so I can parse it in my AJAX and display it but somwhow it ends up with nothing as console.log/etc doesnt display any data.

I had out.append but it also didnt work.

r314
  • 11
  • 4

1 Answers1

0

Use below code to send response as JSON.

response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(obj1);

Please check this How to use Servlets and Ajax?

It will surely help you.

Alien
  • 15,141
  • 6
  • 37
  • 57