title: When I run java servlet to view JSON result -- it pops up file download instead of http://localhost:8080/
body: <p><a href="https://i.stack.imgur.com/B00jg.gif" rel="nofollow noreferrer">gif of file download pop up</a></p>
  
  <p>How can I test the JSON string in the browser without going through the steps of downloading the json file as the File Download dialog pops up when I run the servlet, then viewing the downloaded json file in the browser.</p>
  
  <p>below is the screen shot of postman - postman returns a 404</p>
  
  <p><a href="https://i.stack.imgur.com/Jvjfh.jpg" rel="nofollow noreferrer">postman on localhost 8080</a></p>
  
  <p>below is the web.xml for mapping</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"&gt;
  
    &lt;!-- General Description of the web application --&gt;  
  
    &lt;display-name&gt;webData&lt;/display-name&gt;
    &lt;description&gt;data managed in web data table grid&lt;/description&gt;  
  
       &lt;!-- For directory request --&gt;
  
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  
       &lt;!-- Define servlets --&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;queryreturn&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.queryData.Return.QueryReturn&lt;/servlet-class&gt;  
    &lt;/servlet&gt;
  
       &lt;!-- Note: All &lt;servlet&gt; elements MUST be grouped together and
           placed IN FRONT of the &lt;servlet-mapping&gt; elements --&gt;  
  
     &lt;!-- Define servlet's URL mapping --&gt;    
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;queryreturn&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/queryreturn&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;context-param&gt;
      &lt;description&gt;State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2&lt;/description&gt;
      &lt;param-name&gt;javax.faces.STATE_SAVING_METHOD&lt;/param-name&gt;
      &lt;param-value&gt;client&lt;/param-value&gt;
    &lt;/context-param&gt;
  
    &lt;context-param&gt;
      &lt;param-name&gt;javax.servlet.jsp.jstl.fmt.localizationContext&lt;/param-name&gt;
      &lt;param-value&gt;resources.application&lt;/param-value&gt;
    &lt;/context-param&gt;
  
    &lt;listener&gt;
      &lt;listener-class&gt;com.sun.faces.config.ConfigureListener&lt;/listener-class&gt;
    &lt;/listener&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>below is the bean that generates the JSON string successfully but won't run in the browser</p>
  
  <pre><code>package com.queryData.Return;
  //Import required java libraries
  import java.io.*;
  import java.util.List;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import org.json.JSONObject;
  import com.queryData.main.Main;
  // Extend HttpServlet class
  public class QueryReturn extends HttpServlet 
  {
      private static final long serialVersionUID = 1L;
      public void init() throws ServletException
        {
            // Do required initialization
        }
        public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
                  throws ServletException, IOException
        {
            Main m = new Main();
            List&lt;JSONObject&gt; jObj = m.getJsonObject();
            StringBuilder sb = new StringBuilder();
            for(int i =0 ; i &lt; jObj.size(); i++) 
            {
               sb.append(jObj.get(i).toString());
            }         
            String responseStr = "{\"data\":[" + sb + "]}";
  
            // Set response content type
            response.setContentType("application/json");
            // Actual logic goes here.
            PrintWriter out = response.getWriter();
            out.println(responseStr);
  
        }
        public void destroy()
        {
            // do nothing.
        }
  }
  </code></pre>