如何在几秒钟内自动从一个页面重定向到另一页面
这个想法是显示一个可见几秒钟的PageExpiredPage
,并自动重定向到HomePage
,当网络会话过期。
通过以下代码,PageExpiredPage
将显示一个指向 HomePage
的可添加书签的链接。
PageExpiredPage.html:
Your session expired, log in anew by clicking
<a wicket:id="lnk-home-page" href="#"> here</a>
...
PageExpiredPage.java:
final Application app = Session.get().getApplication();
BookmarkablePageLink<? extends Page> lnkHomePage = new BookmarkablePageLink<? extends Page>("lnk-home-page", app.getHomePage());
add(lnkHomePage);
...
如何在 Wicket 中编写代码,使 PageExpiredPage
在显示时在可配置的秒数后自动重定向到 HomePage
?
The idea is to display a PageExpiredPage
that is visible for a few seconds and automatically redirects to the HomePage
, when the web session expires.
By the following code the PageExpiredPage
displays with a bookmarkable link to the HomePage
on it.
PageExpiredPage.html:
Your session expired, log in anew by clicking
<a wicket:id="lnk-home-page" href="#"> here</a>
...
PageExpiredPage.java:
final Application app = Session.get().getApplication();
BookmarkablePageLink<? extends Page> lnkHomePage = new BookmarkablePageLink<? extends Page>("lnk-home-page", app.getHomePage());
add(lnkHomePage);
...
How to code in Wicket that the PageExpiredPage
, when displayed, automatically redirects to HomePage
after a configurable number of seconds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
比 RedirectPage 更好的解决方案是自定义行为。 RedirectPage 的明显问题是您不能使用公共基类来进行页面布局。
这样您就可以直接传递
getHomePage()
的返回值 - 不需要newInstance()
:A better solution than the RedirectPage is a custom behaviour. The obvious problem with RedirectPage is that you can't use a common base class for the layout of the page.
This way you can pass the return value from
getHomePage()
directly - no need fornewInstance()
:我可能错过了一些东西,但在我看来
RedirectPage
可以做到这一点:构造函数:
RedirectPage
扩展了org.apache.wicket.markup.html.WebPage
并接受org.apache.wicket.Page
作为第一个参数。I may have missed something, but it seems to me that
RedirectPage
can do just that:Constructor:
RedirectPage
extendsorg.apache.wicket.markup.html.WebPage
and accepts aorg.apache.wicket.Page
as first argument.