2

I have made a simple register and login page. After the user successfully registered or logged in, a message will display the result.

This is working fine, but I want it that the text is only displayed for a couple seconds. So after 5 seconds the text is gone.

        int i = ps.executeUpdate();
        if (i > 0) {
            out.print("Successfully logged in...");
            RequestDispatcher rs =    request.getRequestDispatcher("/loggedin.html");
            rs.include(request, response);
        }

I've searched online, but I can't find anything on how to do it. Any tips / comments are welcome!

John Doe
  • 47
  • 1
  • 7

1 Answers1

2

To delete what you've printed you could print the backspace character \b.

So to fit your needs:

String s = "Successfully logged in...";
// better use System.out.print() than out.print() *
System.out.print(s);  
Thread.sleep(2000); // Wait 2 seconds

// print as backspaces as charactes printed using CommonLangs
StringUtils.repeat("\b", s.length);    

// print as backspaces as charactes printed with for loop
for (i = 0; i < s.length; i++) {
    System.out.print("\b");
}

Note: this doesn't work nice in Eclipse console. But works perfect in command console. See also How to get backspace \b to work in Eclipse's console?

* better use System.out.print() than out.print()

Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109