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.
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