简体   繁体   English

JSF使用参数重定向到其他页面

[英]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. 它可以工作,但是URL不变,我必须看到带有参数的新URL。

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() . 使用ExternalContext#redirect()而不是ExternalContext#dispatch()

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

A redirect basically instructs the webbrowser to fire a new HTTP request on the given URL. 重定向基本上会指示Web浏览器在给定的URL上触发新的HTTP请求。 That's also why you see the URL change being reflected in webbrowser's address bar. 这就是为什么您看到URL更改反映在Web浏览器的地址栏中的原因。 A dispatch basically instructs the webserver to use a different source for the current request/response. 调度基本上会指示Web服务器为当前请求/响应使用其他源。 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. 由于这是内部发生的,并且不会以新的HTTP请求结束,因此Web浏览器对此更改一无所知,并且地址栏也不会更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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