重定向
例:http://localhost:8080/Test/MyJsp.jsp
請求URL:http://localhost:8080/Test/
相對路徑,無”/”(容器會相對於原先的請求URL建立完整的URL), 如請求上述URL
Response.sendRedirect(“test.jsp”);
絕對路徑,有”/”(容器會相對於Web應用本身建立完整的URL,如
response.sendRedirect("/Test/MyJsp.jsp");
ps:不能寫在響應之後再調用sendRedirect()
PrintWriter writer =response.getWriter();
writer.write("hh");
writer.flush();
response.sendRedirect("/Test/MyJsp.jsp");
請求分派(頁面轉發) (地址欄沒有變化)
這樣頁面跳轉後請求仍是頁面轉發前的那個請求(轉發時可對請求進行修改)
RequestDispatcherview = request.getRequestDispatcher(“MyJsp.jsp”);
View.forward(request,response);