Solved

a sleep method or a check if a page is loaded method

Posted on 2004-09-14
15
2,004 Views
Last Modified: 2009-12-16
Hello All,

Is it there a method in jsp that can check if a page is entirely loaded?
Or a sleep method that stops execution for a few seconds would also suffice.Btw im not using threads.

Thanks
0
Comment
Question by:CtrlCtrlV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
15 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 12053279
In what context do you need this?

If you need the page to load 100% before you do something, you can put some javascript right at the bottom of the page, then this will only fire when the page is completely loaded into the browser...

Can you give more information, or an example of why and where you would be using this?

to do the sleep method, you can do:

  <%
      try { Thread.sleep( 2000 ) ; } catch( InterruptedException ex ) { }
  %>

to sleep for 2 seconds...
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12053282
but of course, if you sleep inside the jsp, then the page will not be fully sent to the user until it has finished sleeping...
0
 

Author Comment

by:CtrlCtrlV
ID: 12053344

Im creating a new file on my system (windows xp) but it will be only valid if the page is completely loaded. Im thinking of something like:

\\when screen loaded
{
File file = new File("myfile");
}    
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:TimYates
ID: 12053372
can you just put it at the bottom of the jsp?

Or you can add a button to the bottom of the page that the user has to click

Or you could add some javascript to the bottom of the page that submits the page back to the server, and it creates the file then?
0
 

Author Comment

by:CtrlCtrlV
ID: 12053406

I have it already at the bottom of the page but it seems to create the file even though the file page isnt entirely loaded,

>>Or you could add some javascript to the bottom of the page that submits the page back to the server, and it creates the file then?

This could work, could you post code plz?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12053535
You would have to put a bit of javascript at the bottom of the page that posts a form back to the same jsp (with a hidden input in it)

<form id="again"><input type="hidden" name="makeFile" value="yes"></form>

Then, at the bottom of the page...

<SCRIPT language="JavaScript">
document.getElementById( "again" ).submit() ;
</SCRIPT>

Then, in the JSP, if you get the hidden property...make the file:

<%
    if( request.getProperty( "again" ) != null )
    {
        // make the file
    }
%>

But this isn't a very neat solution, and relies on the user having javascript enabled...

Maybe if you explain the context of what you are trying to do, I'll be able to think of a better solution... :-)
0
 

Author Comment

by:CtrlCtrlV
ID: 12057171
Sorry about the delay, javascript will be enabled as this is sytem run over a network.  

>><form id="again"><input type="hidden" name="makeFile" value="yes"></form>

Then, at the bottom of the page...

<SCRIPT language="JavaScript">
document.getElementById( "again" ).submit() ;
</SCRIPT>

Where exactly where do I put all that?

If this works it will be fine :)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12062073
at the bottom of the jsp...inside the <BODY> tag of your html output...

Then, that javascript should be fired when the page has finished loading :-)
0
 

Author Comment

by:CtrlCtrlV
ID: 12062888

That didnt work, The page that i want to check that is loaded has a respone.redirect at the bottom of the page, but its still not showing the page, just redirecting right away from the current page.
0
 

Author Comment

by:CtrlCtrlV
ID: 12062924

Ive also tried putting the Thread.sleep just before the redirect but it just sleeps on the current page and then redirects.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12062938
> The page that i want to check that is loaded has a respone.redirect at the bottom of the page, but its still not showing the page, just redirecting right away from the current page.

!?

Response.sendRedirect will fire immediately, irrespective of whether the user has recieved the html or not

Can you post some of your JSP code?
0
 

Author Comment

by:CtrlCtrlV
ID: 12063024
Sure, here it is:

out.print("<td  width='10' align='left'><font face='Arial Narrow' size='3' color= '#000000'>"+names[ncnt]+" <b>:"+salarys+"</b></font>");

I just want that to be displayed for say 5 seconds and then:

response.sendRedirect("sendtoindex.jsp");
0
 
LVL 35

Accepted Solution

by:
TimYates earned 70 total points
ID: 12063055
At the top of the page, put:

<meta http-equiv="Refresh" content="5;sendtoindex.jsp">

(inside the head block)

get rid of response.sendRedirect...that is fired as soon as the server sees it, before the html gets to the user
0
 

Author Comment

by:CtrlCtrlV
ID: 12063180

Thank you :), I couldnt see the woods from the trees....
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12063222
:-) glad I could help :-)

Good luck with it :-)

Tim
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SimpleDateFormat.parse examples 19 120
servlet concurrency 13 133
memory representation of int[][][] a=new int[2][][]; 10 60
jsp insert to database example 2 88
The following article is comprised of the pearls we have garnered deploying virtualization solutions since Virtual Server 2005 and subsequent 2008 RTM+ Hyper-V in standalone and clustered environments.
Not everyone has adapted to a rapid advancement in technology; there are people who are reluctant or afraid to delve into this brave new world of IT. If you have a friend or a family member who suffers from the so-called technophobia, here is how yo…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question