简体   繁体   中英

JSF redirect to other page with parameter

I'm redirecting to another page:

String uri = "../test/planOutput.jsf?job_id=121250";
FacesContext.getCurrentInstance().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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM