JSP: difference between forward and sendredirect
Response. sendredirect ():
Index. jsp
<%out.println("aaaaaaaaaaaaa");response.sendRedirect("/Forward_sendRedirect/Jsp1.jsp?name=ken");out.println(".....");%>
TranslatedAfter index_jsp.java:
......................
try { response.setContentType("text/html"); pageContext =_jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application =pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.println("aaaaaaaaaaaaa");response.sendRedirect("/Forward_sendRedirect/Jsp1.jsp?name=ken");out.println("....."); } catch (java.lang.Throwable t)
........................
<JSP: forwardpage = ""/>
Index. jsp:
After being translated into index_jsp.java:
......................
try { response.setContentType("text/html"); pageContext =_jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application =pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("
<JSP: Forward page ="Jsp1.jsp"/>
It is equivalent:
_ Jspx_page_context.forward ("jsp1.jsp ");
Return;
About parameter transfer:
Http: // localhost: 8080/forward_sendredirect/index. jsp? Name = Ken
After a jump, it is equivalent to accessing
Http: // localhost: 8080/forward_sendredirect/jsp1.jsp? Name = Ken
The parameter used to access index. jsp is passed to the target jsp1.jsp.
Response. sendredirect () is not acceptable.
Reference of shangxuetang: