Refreshing a JSP page


General J2EE: Refreshing a JSP page

  1. Refreshing a JSP page (2 messages)

    Hi, I am developing an application where a JSP page (index.jsp) is displaying some data from the database. There is an HTML form on the JSP page too. When the user fills in the data and clicks submit, he is redirected to a servlet (via form's action)... the servlet inserts the data into the database and the user is redirected back [Response.sendRedirect("index.jsp")] to the original JSP page. The problem I am facing here is that when the user is back on the original index.jsp page, the newly inserted data is not being displayed on the page. The user MUST refresh the page manually in order to view the new data. How can I display the new data automatically, without the user refreshing the page? PS: I have already tried ... but it is not working... Any help will be greatly appreciated. Thanks.

    Threaded Messages (2)

  2. Re: Refreshing a JSP page[ Go to top ]

    Ideally, you should post the data to the same "action" as the current page, that way you eliminate the cache problem you are experiencing. But, as a workaround for your current problem, you may redirect to index.jsp and adding a random parameter to the url, or a timestamp, etc. Example: redirect to "index.jsp?rnd=12344543" or any analogous parameter. Which parameter you choose is not important, as long as the client browser evaluate the full url as a unique string at each request. /N
  3. Re: Refreshing a JSP page[ Go to top ]

    Better to add the following lines to prevent cache......... response.setHeader("Cache-Control","no-cache"); //HTTP 1.1 response.setHeader("Pragma","no-cache"); //HTTP 1.0 response.setDateHeader ("Expires", 0); //prevents caching at the proxy server