FacesContext 内的请求处理
您好,
此问题来自 回答的问题“https://stackoverflow.com/users/157882/balusc">BalusC。答案摘录如下:
只有在幕后才会发生这种情况 转发由 RequestDispatcher#forward() 需要 地方。在前锋中, servletcontainer 基本上重用了 视图的相同 HTTP 请求/响应 (JSP/XHTML 页面)。它不 强制/指示网络浏览器发送 一个全新的请求。
这意味着每个新视图都是使用前向渲染的。以下是我的问题:
如果是上述情况,那么所有显示的视图都具有相同的请求?。因为,我们总是在地址栏中看到相同的 URL。
是否为新请求保留了前一个请求中的值?
在这种情况下,如果每个请求都相同,那么是否就像在会话中存储很长时间一样。我对 JSF 的视图处理有点困惑。想了解更多JSF的内部工作流程。
- 在
faces-config.xml
中使用
时,地址栏中的URL会改变吗?
HI,
This question is from previously answered question by BalusC. The excerpt of the answer as follows:
This happens only if under the covers
a forward by
RequestDispatcher#forward() takes
place. In a forward, the
servletcontainer basically reuses the
same HTTP request/response for a view
(JSP/XHTML page). It does not
force/instruct the webbrowser to send
a brand new request.
What this means is every new view is rendered using the forward. The following are my questions:
If the above is the case, then all the views displayed with the same request?. Because, we are always seeing the same URL in the address bar.
Is it that the values in the previous request is retained for the new request?
In this case, if every request is same then is it like storing in the session, for long time. I am bit confused on the view handling by JSF. Want to understand more internal work flow of JSF.
When we use the
<redirect/>
infaces-config.xml
, will the URL in address bar get changed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它涉及 HTTP POST 请求并且 JSF bean 操作导航到不同的视图,那么根据 saldo,您确实会在同一请求中拥有两个不同的视图。一个用于初始视图,用于收集/转换/验证必要的请求参数并更新模型值,另一个用于结果视图,用于显示某些结果。
在转发中无法发出新请求。这是相同的请求。
事实绝对不是这样的。至于您的困惑,暂时将 JSF 放在一边并尝试使用普通的普通 JSP/Servlet(这就是 JSF 在幕后使用的内容)可能会有所帮助。我认为以下链接可能有助于获得有关基本 JSP/Servlet 如何工作以及 JSP/Servlet 之上的平均 MVC 框架如何工作的新见解:
是的。 HTTP 重定向发送一个 HTTP
location: newpage.jsf
标头,该标头反过来指示网络浏览器在给定位置触发新的 HTTP GET 请求。这会反映在浏览器地址栏中。您可能需要安装 HTTP 调试工具,例如 Firebug 或 Fiddler2 跟踪 HTTP 流量。您将看到转发发生在同一请求内,并且重定向伴随着新请求。If it concerns a HTTP POST request and the JSF bean action navigates to a different view, then per saldo you will indeed have two different views in the same request. One for the initial view which is been used to gather/convert/validate the necessary request parameters and update the model values and other for the result view which is been used to show some result.
In a forward there's no means of a new request. It's the same request.
This is definitely not the case. As to your confusion, it may help to put JSF aside for a while and go playing with plain vanilla JSP/Servlet (which is what JSF is using under the covers). I think the following links may help in getting new insights about how basic JSP/Servlet works and how the average MVC framework on top of JSP/Servlet works:
Yes. A HTTP redirect sends a HTTP
location: newpage.jsf
header which in turn instructs the webbrowser to fire a new HTTP GET request on the given location. This get reflected in the browser address bar. You may want to install a HTTP debugging tool like Firebug or Fiddler2 to track HTTP traffic. You'll see that a forward happens inside the same request and a redirect comes with a new request.如果网页浏览器中的 url 相同,则可能有两种情况。要么按照他提到的方式转发相同的请求,要么使用相同的 URL 发出新的 GET 请求 [情况较小]
请求的生命周期是从请求到响应。因此,在响应之后,所有具有请求范围的托管 bean 将被销毁。
是的,它会指示浏览器对新 URL 发出新的 GET 请求。
if the url is the same in the web-browser then there can be two cases. either the same request is being forwarded as he mentioned OR new GET request is issued with same URL [which is lesser the case]
request life cycle will be from request to response. so after response all the managed bean with request scoped will get destroyed.
Yes it will instruct browser to issue new GET request for new URL.