My Json Object from postman:
{
"sender":"hello"
}
My servlet dopost
method:
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Gson gs = new Gson();
String chatId = gs.fromJson(req.getParameter("sender"), String.class);
JSONObject obj = new JSONObject();
JSONArray arr= new JSONArray();
try {
obj.put("name", chatId);
arr.add(obj);
}
finally {
}
resp.setContentType("application/json");
resp.setCharacterEncoding("utf-8");
resp.getWriter().println(arr);
}
What am I doing wrong?