title: using getClass().getResourceAsStream() in servlet to access json file data
body: <p>Hi I have a json file stored in the project folder "project/file.json". How can I first, access and read the json file's data from the servlet's <code>doGet()</code>method. Second I want to print the returned data in a separate JSP file. I'm posting here as the last resort since I could not find anything on how to do this. here is my files and my attempt so far</p>
  
  <p>here is file.json</p>
  
  <pre><code>{
      "person": {
          "title": "manager",
          "questions": [
              "name ?",
              "age ?",
              "hobby ?"
          ]
      }
  }
  </code></pre>
  
  <p>here is the doGet () method from fileServlet.java</p>
  
  <pre><code>@Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          processRequest(request, response);
          response.setContentType("text/json");
          /* here I'm accessing the external file JSON file*/
          getClass().getResourceAsStream("project/file.json");
          /* here is where I run into trouble. the StringReader() only
          accepts strings and I cannot figure out how to read the table form
          file.json here*/
          JsonReader reader = Json.createReader(new StringReader(person));
  
          /*the reader needs to be set inorder to create a JsonObject*/
          JsonObject jsonObject = reader.readObject();
      }
  </code></pre>
  
  <p>and finally, the JSP file. I want the file.json items to appear in this form like so</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;form&gt;
              "name ?" get displayed here &lt;br&gt;
              &lt;input type="text" name="firstname" value=""&gt;
              &lt;br&gt;
              "age ?" get displayed here &lt;br&gt;
              &lt;input type="text" name="age" value=""&gt;
              &lt;br&gt;
              "hobby ?" get displayed here &lt;br&gt;
              &lt;input type="text" name="hobby" value=""&gt;
              &lt;br&gt;&lt;br&gt;
              &lt;input type="submit" value="Done"&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Any help or tips will be appreciated</p>