/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] JSP Page reload using JavaScript

Hello,

I have a html page which posts a parameter to JSP. 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.

[upl-file uuid=0acdfcac-3953-4a50-9215-451a3a078cbe size=30kB]prompt.doc[/upl-file]

to post a comment
JavaScript

27 Comments(s)

Copy linkTweet thisAlerts:
@omnicityAug 17.2009 — Have you tried changing your code to explicitly load the required page, instead of doing a reload?
Copy linkTweet thisAlerts:
@IDForumsauthorAug 17.2009 — Could you please explain how should I do that?
Copy linkTweet thisAlerts:
@omnicityAug 18.2009 — Something like:
[CODE]
<body onload="window.setTimeout('window.location="http://www.example.com/myPage.jsp?the=parameters"',604800000);">[/CODE]


but using your own URL, obviously.
Copy linkTweet thisAlerts:
@KuriyamaAug 18.2009 — Hello,

I have a html page which posts a parameter to JSP. 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.[/QUOTE]


You do realize that you are doing with this JavaScript. This page would literally have to be open for a week. What does this page do? What are you trying to accomplish?
Copy linkTweet thisAlerts:
@IDForumsauthorAug 19.2009 — This page displays data from database which is updated only once per week by a cron job. Only after a week there is new data on the page.

There is text on the page which says, last refreshed on: date and time stamp

which lets user know whether the data is updated or not.
Copy linkTweet thisAlerts:
@criterion9Aug 19.2009 — Are you leaving the page open for weeks at a time? Or do you just need to use your server-side language of choice to show the "last updated" tag on the page whenever it is loaded?
Copy linkTweet thisAlerts:
@KuriyamaAug 19.2009 — Are you leaving the page open for weeks at a time? Or do you just need to use your server-side language of choice to show the "last updated" tag on the page whenever it is loaded?[/QUOTE]

Yeah, I don't think you need a body onload event for this. Just change your cron job to write a text file or some DB value as to when it was last updated. This doesn't seem like a good solutions ?
Copy linkTweet thisAlerts:
@IDForumsauthorAug 19.2009 — Here's my code. I implemented the suggested code but no luck. Please let me know where I am doing wrong. I have tried with a small time interval.

<%

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

%>

< body onload="window.setTimeout('window.location="http://iowacwl-cht28j1:8080/expense/index.jsp?costcenter=<%=costCenter%>"',2000);" >

Thanks,

Mona.
Copy linkTweet thisAlerts:
@IDForumsauthorAug 19.2009 — Okay...here's the flow. Pls suggest if this is right.

index.jsp contains instance of a Java class for getting DB connections and querying DB.

Once these results are retrieved these results are displayed in fusion charts and HTML table.

Unless index.jsp is hit by the user the DB connections are not instantiated.
Copy linkTweet thisAlerts:
@criterion9Aug 19.2009 — You just need a last updated blurb. Have your cron job touch a file and get the modified date from the file. The append that date to your page. If you try to refresh the page using javascript it will only work if someone is leaving the page open for a week in their browser.
Copy linkTweet thisAlerts:
@IDForumsauthorAug 19.2009 — If I am doing this in cron job then how should I instantiate DB connections and latest results? I am sorry if I am not understanding you properly. Please explain.

My primary focus here is to hit the database to get updated values each time index.jsp is hit by the user. I understand that if I do it using JS, then it works only if user leaves the page open for a week. I can modify the refresh interval from 1 week to 30 min as well. All I need is to refresh JSP page to hit the DB because index.jsp contains DB Code.

HTML page contains a drop down of all the center numbers. Based on user's selection, this parameter is passed to JSP page which contains DB Code. This particular center number becomes primary key for all the queries. Sorry to bug you.
Copy linkTweet thisAlerts:
@criterion9Aug 19.2009 — You said your cron job updates the database once weekly. That being said the JSP page will load whatever the current data is. A new request is formed each time a form is submitted. So, when you select a new option from the dropdown a new page is formed and thus new db connection. There is no need for an auto refresh at any interval.
Copy linkTweet thisAlerts:
@IDForumsauthorAug 19.2009 — Okay...makes sense.

Does it mean that the user has to go back to the html page and make a selection to view latest data each time?
Copy linkTweet thisAlerts:
@criterion9Aug 19.2009 — Are you using an html page and a jsp page?
Copy linkTweet thisAlerts:
@IDForumsauthorAug 19.2009 — yes..index.html which has drop down list. This selection is passed to index.jsp on request attribute.
Copy linkTweet thisAlerts:
@criterion9Aug 19.2009 — You could build the dropdown into the results page to allow them to pull a new report from your options. Or you could include a "refresh" button and allow the user to refresh. Auto-refreshing an entire page can be very disruptive to users, especially if they are reading something when the page suddenly goes away and comes back differently.
Copy linkTweet thisAlerts:
@IDForumsauthorAug 19.2009 — In either case, how do I send parameter between posts. That was my initial post. When the page is refreshing, it prompts user with a pop up asking resend or cancel. I want to avoid that by simply refreshing the page.

Infact entire page corresponds to particular center number. I think refreshing part of the page will not solve my purpose.
Copy linkTweet thisAlerts:
@criterion9Aug 19.2009 — It sounds like you need a button on the jsp page the reloads the content. You can append your request variable to a query string to use in the href of an a tag. Do you work with JSP often?
Copy linkTweet thisAlerts:
@IDForumsauthorAug 19.2009 — Not very often but if this question is not related to JavaScript then I am sorry. I will try to explore if I can find a solution. If you can think of any solution/example offhand then please post it.
Copy linkTweet thisAlerts:
@criterion9Aug 19.2009 — If your select name is "mySelect" that you are using in your jSP results page. Then you can easily append a refresh link by setting the href to
<i>
</i>your_page.jsp?mySelect=your_select_value

This is more of a JSP question than a javascript question now.
Copy linkTweet thisAlerts:
@omnicityAug 20.2009 — Here's my code. I implemented the suggested code but no luck. Please let me know where I am doing wrong. I have tried with a small time interval.

<%

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

%>

< body onload="window.setTimeout('window.location="http://iowacwl-cht28j1:8080/expense/index.jsp?costcenter=<%=costCenter%>"',2000);" >

Thanks,

Mona.[/QUOTE]


Mona, I am not clear on why this did not work for you. From my understanding of the entire situation this should do what you want, so long as it sits on the JSP page - you didn't have it on the previous (plain HTML) page did you?

If your cron job is running at a specific time, then it might make sense to write a more complex script that checks when the page was last loaded, and refresh it to match your cron job. This could be done either with JavaScript on the client side, or by using JSP to dynamically set the timeout period used by the simple script above.
Copy linkTweet thisAlerts:
@IDForumsauthorAug 20.2009 — Hi there,

I am using this is JSP page and not in HTML. Even my guess is this script should work. Am I doing anything wrong in escaping quotes? Even my eclipse highlights it in red. I tried using a small time interval of 2000ms to test. But the page just sits there without any refresh. When I try to press F5, I am again prompted with RESEND CANCEL pop up. Please suggest.
Copy linkTweet thisAlerts:
@omnicityAug 20.2009 — Could you post the code, as it appears in the browser, ie from 'View Source' not as it appears with JSP tags on the server - there must be something wrong!

Do you get anything in the Error Log in FireFox?
Copy linkTweet thisAlerts:
@IDForumsauthorAug 20.2009 — Please find the attached code.

[upl-file uuid=3b36c63b-6292-4e2f-ab00-55b811430f92 size=13kB]code.txt[/upl-file]
Copy linkTweet thisAlerts:
@omnicityAug 21.2009 — I haven't quite worked out why, but IE tells me that there is an "Unterminated string constant" so I have refactored things slightly.

Insert this:
[CODE]<script>
function refreshFunc()
{
newLoc = "http://iowacwl-cht28j1:8080/expense/index.jsp?costcenter=49146";
alert("newLoc: "+newLoc );
window.location=newLoc;

}
</script>[/CODE]

and then change the BODY tag to:
[CODE]<body onload="window.setTimeout('refreshFunc()',2000);">[/CODE]
and things _should_ work okay.

(Then strip out the Alert box, that is just for extra confirmation.)
Copy linkTweet thisAlerts:
@IDForumsauthorAug 21.2009 — This worked!!!

Thank you for your help and time.

-Mona
Copy linkTweet thisAlerts:
@omnicityAug 24.2009 — No problem, glad that sorted things.
×

Success!

Help @IDForums spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...