Home:ALL Converter>Refresh Java session object in Javascript

Refresh Java session object in Javascript

Ask Time:2011-07-07T11:51:04         Author:newtodatatables

Json Formatter

I am trying to use javascript to do something once it detects a change in the session object. However, javascript does not detect the change in the session object after i have called UpdateServlet. All these is done on the same page (ie. there is no refreshing of page)

Please help! Thanks.

index.jsp

<%
     //initial settings
     session.setAttribute("dataUpdated", "false");   

%>
<script>

   $(function() {
         var updates = '<%=session.getAttribute("dataUpdated")%>';

         alert(updates);
         //Shows false even after update

      if (updates=="true"){
          //alert("Updated");
      }



   });
 </script>

UpdateServlet.java

 protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

       HttpSession session = request.getSession();
       session.setAttribute("dataUpdated", "true");
       //session object set to true

}

Author:newtodatatables,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/6605601/refresh-java-session-object-in-javascript
yy