Dave's Brain

Browse - Programming Tips - How can my servlet return JSON?

Date: 2013may23
Platform: Servlet
Language: Java

Q.  How can my servlet return JSON?

A.  Like this:

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); PrintWriter out = response.getWriter(); out.println("{ \"result\": \"Hello\" }"); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.