request的細節--學習筆記
阿新 • • 發佈:2018-04-18
request的細節--學習筆記)轉發是通過RequestDispatcher對象的forward(request,response)方法完成的
)forward()方法之前的輸出,如果是輸出到緩沖區,再轉發到其他Servlet,那麽原緩沖區的數據忽略不計
)forward()方法之前的輸出,如果真正輸出到瀏覽器,再轉發到其他Servlet,再轉發到其他Servlet代碼忽略不計
)forward()方法之前的輸出,如果是對響應頭的設置,會保留到轉發的其他Servlet中
import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Demo91 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { //response.setContentType("text/html;charset=UTF-8"); //PrintWriter pw = response.getWriter(); //pw.write("Demo91"); //pw.flush(); //pw.close(); //轉發 //request.getRequestDispatcher("/Demo92").forward(request,response); //重定向 response.sendRedirect("/day06/success.html"); } }
轉發java
import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Demo92 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { //輸出 response.getWriter().write("Demo92"); } }
request的細節--學習筆記