How to redirect to another page while keeping the original url?

风流意气都作罢 提交于 2019-12-07 23:51:01

问题


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:


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

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


来源:https://stackoverflow.com/questions/8822137/how-to-redirect-to-another-page-while-keeping-the-original-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!