1 .<logic:forward>属于程序内部访问,一次请求
http://localhost:9999/strutsdemo
2 .<logic:redirect>重定向,发生两次请求
http://localhost:9999/strutsdemo/RegUserUI.htm
<global-forwards>
<forward name="reguserui" path="/RegUserUI.htm"></forward>
</global-forwards>
1. index.jsp中包含<logic:forward name="reguserui"/>时,IE地址显示的是http://localhost:9999/strutsdemo,
forward="reguserui"在index.jsp中没有找到最终画面,但直接转发给了RegUserUI.htm,访问成功
2. index.jsp中包含<logic:redirect forward="reguserui"/>时,IE地址显示的是http://localhost:9999/strutsdemo/RegUserUI.htm,
forward="reguserui"在index.jsp中没有找到最终画面,所以再一次请求RegUserUI.htm,访问成功。
<logic:redirect page="/RegUserUI.htm"/>
http://localhost:9999/strutsdemo/RegUserUI.htm
<logic:redirect href="/strutsdemo/RegUserUI.htm"/>
http://localhost:9999/strutsdemo/RegUserUI.htm
http://localhost:9999/strutsdemo
2 .<logic:redirect>重定向,发生两次请求
http://localhost:9999/strutsdemo/RegUserUI.htm
<global-forwards>
<forward name="reguserui" path="/RegUserUI.htm"></forward>
</global-forwards>
1. index.jsp中包含<logic:forward name="reguserui"/>时,IE地址显示的是http://localhost:9999/strutsdemo,
forward="reguserui"在index.jsp中没有找到最终画面,但直接转发给了RegUserUI.htm,访问成功
2. index.jsp中包含<logic:redirect forward="reguserui"/>时,IE地址显示的是http://localhost:9999/strutsdemo/RegUserUI.htm,
forward="reguserui"在index.jsp中没有找到最终画面,所以再一次请求RegUserUI.htm,访问成功。
<logic:redirect page="/RegUserUI.htm"/>
http://localhost:9999/strutsdemo/RegUserUI.htm
<logic:redirect href="/strutsdemo/RegUserUI.htm"/>
http://localhost:9999/strutsdemo/RegUserUI.htm
本文深入解析了Struts框架中逻辑访问(<logic:forward>)与重定向(<logic:redirect>)的区别及实现原理,通过实际例子展示了两者在不同场景下的应用,帮助开发者理解其工作流程并正确使用。
688

被折叠的 条评论
为什么被折叠?



