[英]Is there any difference between dispatcher.forward() and <jsp:forward>?
Are the following operations exactly identical : 以下操作完全相同:
request.setAttribute(name,"visited");
requestDispatcher.forward(request,response)
and 和
<jsp:forward page="page.jsp">
<jsp:param name="status" value="visited"/>
</jsp:forward>
There is no functional difference. 没有功能差异。 Both <jsp:forward>
and RequestDispatcher.forward() are same in fact <jsp:forward>
internally used the RequestDispatcher.forward()
to forward the request. <jsp:forward>
和RequestDispatcher.forward()实际上是相同的<jsp:forward>
内部使用RequestDispatcher.forward()
来转发请求。 is action tag and there is tag handler class . 是动作标签,还有标签处理程序类。 Always remember JSP also going convert to a servlet, by the web container. 永远记住JSP也会通过Web容器转换为servlet。
If only consider the forward action, there is no functional diffrerence. 如果只考虑前向行动,则没有功能差异。 But they seems not fully the same. 但它们似乎并不完全相同。 I test the following code. 我测试以下代码。
<%
System.out.println("source 1");
RequestDispatcher disp = request.getRequestDispatcher("1_f1.jsp");
disp.forward(request, response);
System.out.println("source 2");
%>
and 和
<%
System.out.println("source 1");
%>
<jsp:forward page="1_f1.jsp"/>
<%
System.out.println("source 2");
%>
When using disp.forward()
, console will output "source 2". 使用disp.forward()
,控制台将输出“source 2”。 But when using <jsp:forward/>
, "source 2" will not be output. 但是当使用<jsp:forward/>
,不会输出“source 2”。
The is converted to the following statements. 转换为以下语句。
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
if (true) {
_jspx_page_context.forward("1_f1.jsp");
return;
}
Here is a return;
这是return;
statement. 声明。 So, the code after <jsp:forward/>
will not run. 因此, <jsp:forward/>
之后的代码将无法运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.