-1

Here in my registration page i did servlet page in insert values to Data Base and i need to display all the insert values from Data Base in html table using in jsp when i enter all the details click add button it shows message in another page when i go back to the previous page table not update with latest values when i reload page it shows values how can i do this

my image after clicking add button table not updated: image description here

Jhon
  • 33
  • 11
  • Please read [How to ask](http://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve), and update your question then. In short: do not write an essay explaining what you (want to) do, **show your code** instead (what have you tried so far). – Jozef Chocholacek Apr 05 '17 at 13:06

1 Answers1

0

Call page reload with javascript, on button press. You can do this in two ways:

1)

<input type="submit" value="submit" onsubmit="window.location.reload()"/>

in case it doesn't work, check the first answer on How can I refresh a form page after the form submits to _blank?

2)

<input type="submit" value="submit" onclick="refresh()" />

add the following javascript code just below:

   <script type="text/javascript">
   function refresh (){ 
      window.location.reload();
   }
   </script>

The above two solutions are equivalent. A different approach is to set the meta attribute of the html page, specifying the refresh interval. Please take a look at https://www.codeproject.com/Questions/250016/refresh-the-jsp-page

That gives a third solution:

3)

<%
    if(session.getAttribute("refreshCount") != null &&
        session.getAttribute("refreshCount") == true   ) 
    {
        response.setHeader("REFRESH", "0");   //refresh page once per submit
        session.setAttribute("refreshCount", false);
    }
%>

In the servlet, when you save data to database, also call

HttpSession session=request.getSession();  
session.setAttribute("refreshCount",true); 

4) In the servlet, use redirect instead of forward (you will be redirecting to the same page)

how to reload JSP page after submit form data

http://www.javapractices.com/topic/TopicAction.do?Id=181

Community
  • 1
  • 1
Newton fan 01
  • 484
  • 5
  • 14
  • Hi,@Nweton fan, I did insert code in servlet page when i get a message it shows url like this `/UserRegistrationServlet` initially url is `/UserRegistration.jsp` is it possible to show message also in same page – Jhon Apr 06 '17 at 04:31