【问题标题】:Display text only for a couple seconds仅显示文本几秒钟
【发布时间】:2015-04-26 09:49:29
【问题描述】:

我已经做了一个简单的注册和登录页面。 用户成功注册或登录后,将显示一条消息。

这工作正常,但我希望文本只显示几秒钟。所以 5 秒后文本消失了。

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

我在网上搜索过,但找不到任何有关如何操作的信息。 欢迎任何提示/ cmets!

【问题讨论】:

标签: java time


【解决方案1】:

要删除您打印的内容,您可以打印退格字符\b

为了满足您的需求:

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");
}

注意:这在 Eclipse 控制台中效果不佳。但在命令控制台中完美运行。另见How to get backspace \b to work in Eclipse's console?

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

【讨论】:

  • System.out.println 是一个调试语句。我相信 OP 实际上是将用户发送到网页。
猜你喜欢
  • 2019-02-27
  • 1970-01-01
  • 1970-01-01
  • 2017-07-12
  • 1970-01-01
  • 2011-12-16
  • 2011-12-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多