Fetching JSON object from Servlet Java

Posted by ChrisA on Stack Overflow See other posts from Stack Overflow or by ChrisA
Published on 2012-12-09T04:46:06Z Indexed on 2012/12/09 5:04 UTC
Read the original article Hit count: 211

Filed under:
|
|
|
|

I want to create an application that will fetch a JSON object from a servlet to deserialize it, and then use its variables to do other things.

My servlet has the following code in the 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();

    }

Now, while the servlet is running, I can access it via a browser, if I post same code in the doGet method, that would download a servlet file, which is not what I want.

What should I use in my second application that would connect to the servlet, fetch the object, so that I can manipulate it later?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about java

Related posts about JSON