如何将JSON数据发送到我的Servlet的doPost()
方法并将其接收回来?我有一个生成并使用JSON的Web服务。
答案 0 :(得分:3)
使用在servlet中传递给doPost方法的HttpServletRequest和HttpServletResponse参数
public class ExampServlet extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
{
// to accept the json data
String jsonData = request.getParameter("json");
// to send out the json data
response.setContentType("application/json");
PrintWriter out = response.getWriter();
out.println(jsonData) ;
out.close() /
}