Two things the other two responses said are both correct (from what i know).
It sounds like you are either trying to display the first page, then
"transition" to the second page 5 seconds later. OR, you might be trying to
show the first page, then "append" the second page to the first one.
Remember your dealing with web browsers.

So, in the first case, if you want a 5 sec delay, then a second page to show
up, your better off using a JavaScript timer, or a META statement (forget
both, but you can do a search on google and dig them up on how to do this).
This way you send back a page and close the connection to the server. Then,
the browser with its javascript or meta tag, after 5 seconds, sends another
request to get the second page. There is one very important reason why if
this is what your trying to do, its the right way. Scalability/performance!
If you try to do it your way, you are tying up a server thread/connection
for x number of seconds to send back that second page. If your site gets hit
by a lot of people, each and every connection you can alot is needed, and by
tying up a connection for this long, its a sure way of seeing bad site
response times, unless you have an unlimited budget and can buy lots of
servers and a good load balancer. On the other hand, this is one way you can
do a page transition, such as what www.orbitz.com does when you go do a
search. It displays the animted image and while leaving the connection open,
it fetches the data then returns that information through that same
connection. So, for a "please wait.." type of screen, this may not be a bad
idea. I did the same thing with an animated GIF, but I had mixed results
because for some reason, the animted gif stopped animating as soon as I sent
another request from within the same frame of the animated gif. You have to
use two frames (a hidden one) that then fetches the new page (or does the
query) and so on.

In the second case, I believe as one person said, FLUSH the output stream
after the first page, then grab the next one. The problem with this approach
is that it is possible you may try to set the content header again in the
second page, which will throw an exception. Since I haven't worked on
JSP/Servlets for a few months, my memory is faultering a little bit here,
but if I recall, once you set the content type and start sending data back,
you can not change the content type or set it again. By using two different
pages, especially JSP pages, it is possible that the java code created by
the JSP engine would result in the 2nd JSP page performing this and could
cause problems. You could make a URL connection to each JSP page, get is
"rendered" HTML output, and append that, but then your making 3 connections
(the original, plus the two for each JSP page) and thus reduce performance
that much more.

At any rate, good luck.


> -----Original Message-----
> From: Kam Premkumar [mailto:[EMAIL PROTECTED]]
> Sent: Friday, December 14, 2001 9:46 AM
> To: [EMAIL PROTECTED]
> Subject: thread sleep between jsp includes
>
>
> please look at the code . I am trying to include one .jsp and  making
> the current thread to sleep for 5 sec then icluding one more jsp. But
> both included jsps coming to screen same time > i included
> the code for
> your refernce guys.
>
> Thanks
> Prem
>
> import java.io.*;
> import java.text.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
>
> public class HelloWorldExample extends HttpServlet {
>
>    public void doGet(HttpServletRequest request, HttpServletResponse
> response)    throws IOException, ServletException
>     {
>          response.setContentType("text/html");
>          PrintWriter out = new PrintWriter(response.getWriter(),true);
>
>         String inxml="HelloWOrld";
>         request.setAttribute("myData", inxml );
>
> getServletConfig().getServletContext().getRequestDispatcher("/
> jsp/test.jsp").include(request,
> response);
>
>         try
>         {
>             System.out.println("Entering into the loop 1");
>             Thread.currentThread().sleep(5000);
>         }
>         catch(Exception ex1)
>         {
>             System.out.println(ex1.getMessage());
>         }
>
>         String inxml1="Helo WOrld1";
>         request.setAttribute("myData1", inxml1 );
>
> getServletConfig().getServletContext().getRequestDispatcher("/
> jsp/test1.jsp").include(request,
> response);
>
>     }
> }
>
>
> test.jsp
> ========
> <%
> String s =(String)request.getAttribute("myData");
> out.println(s);
> %>
>
>
> test1.jsp
> ========
> <%
> String s1 = (String)request.getAttribute("myData1");
> out.println(s1);
> %>
>
> ==============================================================
> =============
> To unsubscribe: mailto [EMAIL PROTECTED] with body:
> "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set
> JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://archives.java.sun.com/jsp-interest.html
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.jsp
>  http://www.jguru.com/faq/index.jsp
>  http://www.jspinsider.com
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to