如何在保留原始网址的同时重定向到另一个页面? [英] How to redirect to another page while keeping the original url?

查看:138
本文介绍了如何在保留原始网址的同时重定向到另一个页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Wicket 1.5 Web应用程序中,我想重定向到另一个可添加书签的页面,而原始页面的 URL应该保留.

In my Wicket 1.5 web application, I want to redirect to another bookmarkable page, whilst the URL of the originating page should remain.

@MountPath(value="page1")
public class WebPage1 extends WebPage {

    public WebPage1() {
        ...
        if (!isDisplayable()) {
            setResponsePage(WebPage2.class);
            // throw new RestartResponseException(Error404WebPage.class);
            // throw new RestartResponseAtInterceptPageException(Error404WebPage.class);
        }
    }

    private boolean isDisplayable() {
        boolean flag = ...
        ...
        return flag;
    }
}

@MountPath(value="page2")
public class WebPage2 extends WebPage {

    public WebPage2() {
    }

    public WebPage2(PageParameters params) {
    }
}

使用setResponsePage(..)的方法,抛出新的RestartResponseException(..)或抛出新的RestartResponseAtInterceptPageException(..)的方法都不会使URL保持不变. 这三种方法都重定向到Page2 ,并且更改浏览器地址栏中显示的URL.

Neither of the approaches with setResponsePage(..), throw new RestartResponseException(..) or throw new RestartResponseAtInterceptPageException(..) leaves the URL unchanged. All three methods redirect to Page2 and change the displayed URL in the browser's address bar.

推荐答案

您应为RestartResponseException提供RedirectPolicy.NEVER_REDIRECT.即

throw new RestartResponseException(new PageProvider(Error404Page.class), RedirectPolicy.NEVER_REDIRECT);

这篇关于如何在保留原始网址的同时重定向到另一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆