How to redirect to another page while keeping the

2019-05-26 01:21发布

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) {
    }
}

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.

1条回答
姐就是有狂的资本
2楼-- · 2019-05-26 02:02

You should supply the RestartResponseException with RedirectPolicy.NEVER_REDIRECT. I.e.

throw new RestartResponseException(new PageProvider(Error404Page.class), RedirectPolicy.NEVER_REDIRECT);
查看更多
登录 后发表回答