title: Logged in user`s info disappearing after he goes back to homepage in JSP
body: <p><img src="https://i.stack.imgur.com/E9jOe.png" alt="enter image description here"><img src="https://i.stack.imgur.com/Rei5S.png" alt="enter image description here"><img src="https://i.stack.imgur.com/vL4SB.png" alt="enter image description here"></p>
  
  <p>In the following code after log in, user can view his info and then to click add/delete or edit buttons and be redirected to corresponding page. But after he edits information and presses "View Menu" button, he is redirected back but his info is no longer visible, just a headers of table. First picture from top to bottom is the view when user logs in, second one is when he adds new menu, and third one is what happens when he goes to his home screen again. How can i update "View Menu" after user adds info.</p>
  
  <pre><code>&lt;%@ page language="java" import="java.sql.*" import="java.text.*" errorPage="" %&gt;
  &lt;%
  String myname = (String)session.getAttribute("username");
  
  Connection conn = null;
  Class.forName("com.mysql.jdbc.Driver").newInstance();
  conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root",     "root");
  
  ResultSet rsLoginFunction = null;
  PreparedStatement psLoginFunction=null;
  
      String sUserID=request.getParameter("username");
  String sPassword=request.getParameter("password");
  String message="User login successfully ";
  
  try{
    String sql = "SELECT menu.name, menu.info, menu.price FROM menu INNER JOIN clients ON     menu.username = clients.username where clients.username=? and clients.password=?";
  psLoginFunction=conn.prepareStatement(sql);
  psLoginFunction.setString(1,sUserID);
  psLoginFunction.setString(2,sPassword);
  
  rsLoginFunction=psLoginFunction.executeQuery();
  
  session.setAttribute("username", sUserID);
  
  if(rsLoginFunction.next())
  {
    String username=rsLoginFunction.getString("menu.name")+"     "+rsLoginFunction.getString("menu.info");
  
  
   }
  else
  {
    message="No user or password matched" ;
    response.sendRedirect("Login.jsp?error="+message);
  }
  }
  catch(Exception e)
  {
      e.printStackTrace();
  }
  
  
  /// close object and connection
  try{
       if(psLoginFunction!=null){
           psLoginFunction.close();
       }
       if(rsLoginFunction!=null){
           rsLoginFunction.close();
       }
  
       if(conn!=null){
        conn.close();
       }
  }
  catch(Exception e)
  {
      e.printStackTrace();
  }
  
  %&gt;
  </code></pre>
  
  <p>here is client info page</p>
  
  <pre><code>&lt;%@ include file="include/common.jsp"%&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
  
  
  
  
  &lt;script type="text/javascript"&gt;
  
  function del() {
      if (confirm("Do You Want to Delete this Menu?")) {
      } else {
          return false;
      }
  }
  &lt;/script&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;link rel="stylesheet" href="images/style.css" type="text/css"
  charset="utf-8" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;%
  
      menu_slno1 = request.getParameter("menu_slno");
      if (menu_slno1 != null)
          menu_slno = Integer.parseInt(menu_slno1);
      delete_menu = request.getParameter("delete_menu");
  
  
      if ("yes".equals(delete_menu)) {
          MenuId = request.getParameter("MenuId");
          x = stmt1
                  .executeUpdate("Delete from menu where MenuId="
                          + MenuId);
      }
  %&gt;
  
  
  &lt;center&gt;&lt;h2&gt;VIEW MENU&lt;/h2&gt;&lt;/center&gt;
  
  &lt;center&gt;&lt;table width="736" height="97" border="1"&gt;&lt;/center&gt;
      &lt;%
          if (x == 1) {
      %&gt;
      &lt;tr bgcolor="gray"&gt;
          &lt;th height="35" colspan="9"&gt;&lt;div align="center"&gt;
                  Menu deleted successfully!
              &lt;/div&gt;&lt;/th&gt;
      &lt;/tr&gt;
      &lt;%
          }
      %&gt;
      &lt;tr bgcolor="gray"&gt;
          &lt;td&gt;&lt;div align="center"&gt;
                  &lt;strong&gt;Menu ID&lt;/strong&gt;
              &lt;/div&gt;&lt;/td&gt;
          &lt;td&gt;&lt;div align="center"&gt;
                  &lt;strong&gt;Name &lt;/strong&gt;
              &lt;/div&gt;&lt;/td&gt;
          &lt;td&gt;&lt;div align="center"&gt;
                  &lt;strong&gt;Info&lt;/strong&gt;
              &lt;/div&gt;&lt;/td&gt;
          &lt;td&gt;&lt;div align="center"&gt;
                  &lt;strong&gt;Price&lt;/strong&gt;
              &lt;/div&gt;&lt;/td&gt;
          &lt;td colspan="2"&gt;&lt;div align="center"&gt;
                  &lt;strong&gt;Action&lt;/strong&gt;
              &lt;/div&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;%
  
       String sUserID=request.getParameter("username");
        session.setAttribute("username", sUserID);
          int icount = 0;
          rs = stmt.executeQuery("SELECT menu.menuID, menu.name, menu.info,     menu.price, menu.RestaurantID  FROM menu INNER JOIN clients ON menu.username =     clients.username where menu.username='" +sUserID+ "'");
  
          while (rs.next()) {
              //menu_slno = rs.getInt("menu_slno");
              MenuId = rs.getString("MenuId");
          %&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;div align="center"&gt;&lt;%=++icount%&gt;&lt;/div&gt;&lt;/td&gt;
  
          &lt;td&gt;&lt;%=rs.getString("Name")%&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%=rs.getString("Info")%&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%=rs.getDouble("Price")%&gt;&lt;/td&gt;
  
          &lt;td&gt;&lt;div align="center"&gt;
                  &lt;a href="edit_menu.jsp?MenuId=&lt;%=MenuId%&gt;"&gt;Edit&lt;/a&gt;
              &lt;/div&gt;&lt;/td&gt;
          &lt;td&gt;&lt;div align="center"&gt;
                  &lt;a
                      href="view_menu.jsp?delete_menu=yes&amp;MenuId=    &lt;%=MenuId%&gt;&amp;MenuId=&lt;%=MenuId%&gt;"
                      onclick="return del()"&gt;Delete&lt;/a&gt;
              &lt;/div&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;%
          }
      %&gt;
  &lt;/table&gt;
  &lt;a href="add_menu.jsp"&gt;Add Menu&lt;/a&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and the last page where user adds new info (not editing or deleting just adding new)</p>
  
  <pre><code>&lt;%@ include file="include/common.jsp"%&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;link rel="stylesheet" href="images/style.css" type="text/css"
  charset="utf-8" /&gt;
  
  &lt;script language="javascript"&gt;
  function validate(menu) {
  
  
  //  request.setAttribute("user","&lt;username&gt;");
  //  String user=request.getAttribute("user");
  //  while (username.equals(sUserID))
  
  
  
          if (menu.Name.value.length == 0) {
          alert("Please enter Menu Name!");
          menu.Name.focus();
          return false;
      }
  
      if (menu.Info.value.length == 0) {
          alert("Please enter Menu Info!");
          menu.Info.focus();
          return false;
      }
  
      if (menu.Price.value.length == 0) {
          alert("Please enter price!");
          menu.Price.focus();
          return false;
  
  
      }
  
      return true;
  
  }
  &lt;/script&gt;
  
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h2&gt;ADD MENU&lt;/h2&gt;
  &lt;form name="menu" id="menu" action="db_add_menu.jsp"
      method="post" onSubmit="return validate(this)"&gt;
      &lt;table width="332" height="252" border="0" align="center"
          cellpadding="2" cellspacing="2"&gt;
          &lt;tr&gt;
              &lt;th height="33" colspan="2"&gt;&lt;div align="center"&gt;
                      &lt;%
                          menu = (String)     session.getAttribute("menu");
                          session.removeAttribute("menu");
                          if (menu != null)
                              out.print(menu);
  
  
  
                      %&gt;
                  &lt;/div&gt;&lt;/th&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;th&gt;Menu Name&lt;/th&gt;
              &lt;td&gt;&lt;input name="Name" type="text" class="text"
                  id="Name" value="" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;Menu Info&lt;/th&gt;
              &lt;td&gt;&lt;input name="Info" type="text" class="text"
                  id="Info" value="" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;Menu Price&lt;/th&gt;
              &lt;td&gt;&lt;input name="Price" type="text" class="text"
                  id="Price" value="" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td class="submission" colspan="2"&gt;&lt;div align="center"&gt;
                      &lt;input name="s" type="submit" class="button" value="ADD" /&gt; &lt;input
                          name="Reset" type="reset"     class="button" value="RESET" /&gt;
                  &lt;/div&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th class="submission" colspan="2"&gt;&lt;div align="center"&gt;
                      &lt;a href="view_menu.jsp"&gt;View Menu&lt;/a&gt;
                  &lt;/div&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  
  &lt;/form&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Last page in case you need it is a function of adding info:</p>
  
  <pre><code>&lt;%@ include file="include/common.jsp" %&gt;
  
  &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"     "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  body&gt;
  
  &lt;%
  
   String myname = (String)session.getAttribute("username");
  
      MenuId = request.getParameter("MenuId");
      Name = request.getParameter("Name");
      Info = request.getParameter("Info");
      RestaurantID = request.getParameter("RestaurantID");
  
      menu_price1 = request.getParameter("Price");
      if (menu_price1 != null || !"".equals(menu_price1))
          Price = Double.parseDouble(menu_price1);
  
  
      pstmt = con
              .prepareStatement("Insert into     menu(MenuId,Name,Info,Price,RestaurantID) values(?,?,?,?,?)");
      pstmt.setString(1, MenuId);
      pstmt.setString(2, Name);
      pstmt.setString(3, Info);
      pstmt.setDouble(4, Price);
      pstmt.setString(5, myname);
      pstmt.executeUpdate();
  
      con.close();
      session.setAttribute("menu", "Menu added successfully");
      response.sendRedirect("add_menu.jsp");
  %&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>