code: public static void respondAsHtmlUsingJsonAndTemplateWithHttpStatus(HttpServletResponse resp, Object response,
              String resourcePageTemplate, int statusCode) throws IOException {
          resp.setContentType("text/html");
          resp.setCharacterEncoding("UTF-8");
          resp.setStatus(statusCode);
  
          String template = IOUtils.toString(ServletHelper.class.getResourceAsStream(resourcePageTemplate), "UTF-8");
          final String json = new GsonBuilder().serializeNulls().create().toJson(response);
          final String jsonUtf8 = new String(json.getBytes(), "UTF-8");
          template = String.format(template, jsonUtf8);
          resp.getOutputStream().print(template);
          resp.flushBuffer();
      }
docs: Sends a HTTP response as a text/html document and with a HTTP status code. Injects a json object into the
  template before responding.
  
  @param resp
  A {@link HttpServletResponse} object that the servlet is responding on.
  @param response
  The response object which will be serialized to a JSON document.
  @param resourcePageTemplate
  The HTML template to use which is loaded as a classpath resource.
  @param statusCode
  The HTTP status code to send with the response.
  @throws IOException