开发者

JSF redirect to other page with parameter

开发者 https://www.devze.com 2023-02-17 22:58 出处:网络
I\'m redirecting to another page: String uri = \"../test/planOutput.jsf?job_id=121250\"; FacesContext.getCurrent开发者_如何学运维Instance().getExternalContext().dispatch(uri);

I'm redirecting to another page:

String uri = "../test/planOutput.jsf?job_id=121250";
FacesContext.getCurrent开发者_如何学运维Instance().getExternalContext().dispatch(uri);

It works, but the URL doesn't change, I must see the new URL with the parameter.

What is the solution?


You aren't redirecting the request to a different target at all. You are dispatching the request to a different source. Use ExternalContext#redirect() instead of ExternalContext#dispatch().

FacesContext.getCurrentInstance().getExternalContext().redirect(uri);

A redirect basically instructs the webbrowser to fire a new HTTP request on the given URL. That's also why you see the URL change being reflected in webbrowser's address bar. A dispatch basically instructs the webserver to use a different source for the current request/response. Since this happens internally and does not end up in a new HTTP request, the webbrowser know nothing about the change and the address bar won't be changed.

0

精彩评论

暂无评论...
验证码 换一张
取 消