IDForums

JSP Page reload using JavaScript

Recommended Posts

Hello,

 

 

 

I have a html page which posts a parameter to JSP. This parameter is used to query against database and display results in FusionChart and also in HTML Table. This jsp page has to be refreshed once in a week.

 

 

 

< body onload="window.setTimeout('window.location.reload()',604800000);">

 

 

 

I used the above onload function to achieve this. But every time the page reloads, user is prompted with a pop up saying:

 

 

 

To display the page, Firefox must send information that will repeat any action(such as a search or order confirmation) that was performed earlier.

 

 

 

Resend Cancel

 

 

 

Is there anyway that I can avoid this prompt?

 

Please find the attachment for your reference.

 

 

 

Thanks.

prompt.doc

Edited by Guest

Share this post


Link to post
Share on other sites

Hi,

 

 

 

There is one parameter from HTML page to this JSP page. How can I handle this?

 

Here are more details:

 

< % String centerName = request.getParameter("centerName"); % >

 

 

 

Thanks.

Edited by Guest

Share this post


Link to post
Share on other sites

Hi,

 

 

 

As in my first post, I am using this parameter to query DB to display results in JSP page.

 

Here's the flow:

 

HTMl displays a drop down for all the center names. Based on user selection, this center name is passed to JSP page which contains Fusion Chart and also HTML table. This particular center name is the basis for querying DB and displaying results. I cannot avoid this parameter.

 

 

 

Please suggest.

Share this post


Link to post
Share on other sites

Hello,

 

 

 

I tried using cookies. Here is my code:

 

< % String costCenter = request.getParameter("costcenter");

 

if(costCenter == null)

 

costCenter = "";

 

Cookie cookie = new Cookie(costCenter, "costCenter");

 

cookie.setMaxAge(60*60);

 

response.addCookie(cookie);

 

% >

 

 

 

< body onLoad="window.setTimeout(window.location='index.jsp?costCenter='+costCenter, 604800000);" >

 

 

 

Let me know if this is right.

 

 

 

Thanks.

Share this post


Link to post
Share on other sites

Hi

Here is the code that you would need in index.jsp

<% 
String costCenter = request.getParameter("costcenter");
//Check if the cookie is already present and use that value, if request parameter is not present.
String cookieName = "costCenter";
Cookie cookies [] = request.getCookies ();
Cookie centerCookie = null;
if (cookies != null)
{
 for (int i = 0; i < cookies.length; i++) 
 {
 if (cookies [i].getName().equals (cookieName))
 {
  centerCookie = cookies[i];
  break;
 }
 }
}
if(costCenter == null) {
 if(centerCookie!=null) {
 costCenter = centerCookie.getValue();
 System.out.println("centerCookie "+centerCookie.getValue());
 }
 else {
 costCenter ="";
 }
}
if(!costCenter.equals("") || centerCookie==null) {
 //Set the cookie
 Cookie cookie = new Cookie("costCenter",costCenter);
 cookie.setMaxAge(60*60);
 response.addCookie(cookie);
}
%>
<script>
function reloadPage() {
 window.location='index.jsp';
}
</script>
<html>
<body onload="setTimeout('reloadPage()',3000)" >
This page refreshes itself without any dialog. <%= costCenter %>
</body>
</html>

Please put a suitable timeout value.

Hope this helps!

Srividya

Edited by Guest

Share this post


Link to post
Share on other sites

Hi srividya,

 

 

 

Thanks for your help. I think a recursive call is occurring somewhere. My page is refreshing continuously in a loop even though I am taking care of the time out interval.

 

 

 

Thanks.

Share this post


Link to post
Share on other sites

Hi

Please use the following code in the body tag:

<body onload="timer=setTimeout('reloadPage()',604800000)" >

and the reloadPage as defined below:

function reloadPage() {
 window.location='index.jsp';
}

Srividya

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now