Execute RequestDispatcher after 5 seconds

555 views Asked by At

I use jsp and servlets and I would like to execute a RequestDispatcher after 5 seconds.

request.getRequestDispatcher("/WEB-INF/page.jsp").forward(request, response);

Is there some kind of wait.time(5000)?

edit: I still would be interested in a solution!

1

There are 1 answers

2
javapointdotcom On

Simply use Thread.sleep(5000) or the below approach

new java.util.Timer().schedule( 
        new java.util.TimerTask() {
            @Override
            public void run() {
                // your code here
            }
        }, 
        5000 
);

Hope this solves your expectations.