aspose file tools
The moose likes JSP and the fly likes Is there any way to delay including a page in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Is there any way to delay including a page in jsp" Watch "Is there any way to delay including a page in jsp" New topic
Author

Is there any way to delay including a page in jsp

Neil Grace
Greenhorn

Joined: Oct 03, 2011
Posts: 2
I have two includes in my jsp. What i want to do is make the second include after some delay. How can I do that? Thanks.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62508
    
  68

You can't. Not with JSP technology, at least.

What you need to do is to start a JavaScript timer when the page loads, and when the timer expires, grab the page fragment to be included via an Ajax request.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62508
    
  68

This is almost trivial with jQuery's help.

Put an empty div in the page where the delayed content is to be placed, like:
Then use the following script:
This will fetch the delayed content 1 second after the page loads and stick it into the empty div.
Neil Grace
Greenhorn

Joined: Oct 03, 2011
Posts: 2
Thanks for the reply. What I am trying to achieve is:

I want to show Page2.jsp based on a session attribute that will be set by the AJAX call from Page1.jsp. So I want to delay the displaying of page2.jsp and subsequent page unless I get response back from AJAX call made.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62508
    
  68

The instead of doing it in a ready handler with a timeout as I showed, you'd do the .load() in the success handler of the previous Ajax request. Why didn't you put all that in the initial topic?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Is there any way to delay including a page in jsp