title: JSP refresh page through servlet
body: <p>I'd like to using servlet code to refresh jsp page.</p>
  
  <p>The "my_list.jsp" is a page with a list of items
  The "my_add.jsp" is a page that user can input something to add items to the list in "my_list.jsp"</p>
  
  <p>The following figure is the current design.</p>
  
  <p><img src="https://i.stack.imgur.com/Yxjz1.png" alt="enter image description here"></p>
  
  <p>User click "add items" in "my_list.jsp" and there will be a pop-up "my_add.jsp".
  After user finishes inputing and click "Add button" to add the item to the list, it will trigger "AddServlet.java" to add the item.</p>
  
  <pre><code>AddServlet.java
  
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
  
      AddItem();
      resp.sendRedirect("/my_add.jsp");
      resp.setHeader("REFRESH", "0");
  }
  </code></pre>
  
  <p>Because the user may add more items, so I don't want "my_add.jsp" page close after adding an item.
  So I write the following in "AddServlet.java"</p>
  
  <pre><code>resp.sendRedirect("/my_add.jsp");
  resp.setHeader("REFRESH", "0");
  </code></pre>
  
  <p>But now, after user clicks "Add button" in "my_add.jsp" page, "my_list.jsp" will not update. "my_list.jsp" will update only if I click "Close button" in "my_add.jsp" or press "Refresh" in "my_list.jsp".</p>
  
  <p>I would like to know if there's any way to refresh "my_list.jsp" page after clicking "Add button" in "my_add.jsp" ?</p>
  
  <p>Thanks in advance.</p>
  
  <p>Eric</p>