Java Servlet return JSON Object in response

I am calling a java servlet when a form is submitted like this

<form action="/doStuff" method="post" enctype="multipart/form-data">

In side my servlet I do some stuff and make a Object, and now I want to go back to the page where the call was made and give that page this data.

So I am currently doing this

String json = new Gson().toJson(packingListData);
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(json);
        response.sendRedirect("/home.jsp");

If I leave of response.sendRedirect("/home.jsp"); this line I see the object printed out of the page localhost:9080/doStuff

So how can I go back to the page the form was submitted on and get that data?

Thanks

链接地址: http://www.djcxy.com/p/46076.html

上一篇: 在spring mvc和hibernate中将动态数据保存到数据库

下一篇: Java Servlet返回JSON对象作为响应