我想创建一个应用程序,该应用程序将从 servlet 获取 JSON 对象以反序列化它,然后使用它的变量来做其他事情。
我的 servlet 在 doPost 中有以下代码:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ObjectOutputStream os;
os = new ObjectOutputStream(response.getOutputStream());
String s = new String("A String");
Gson gson = new Gson();
String gsonObject= gson.toJson(s);
os.writeObject(gsonObject);
os.close();
}
现在,当 servlet 运行时,我可以通过浏览器访问它,如果我在 doGet 方法中发布相同的代码,那将下载一个 servlet 文件,这不是我想要的。
我应该在我的第二个应用程序中使用什么来连接到 servlet,获取对象,以便以后可以操作它?
提前致谢。