public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //接受用戶的用戶名和密碼 String uname = request.getParameter("uname"); String passwd = request.getParameter("passwd"); //驗證用戶名和密碼 if(uname.equals("zhangsan") && passwd.equals("1234")){ //去主頁操做 //請求轉發 request.getRequestDispatcher("index.jsp").forward(request, response); }else{ //跳回登陸頁面,繼續登陸 //重定向 response.sendRedirect("login.html"); } }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("aaa", "bbb"); request.getRequestDispatcher("des").forward(request, response); }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("aaa", "ccc"); response.sendRedirect("dest"); //重定向的特色: //1.地址欄會發生改變 //2.用戶發起了兩次請求 //3.重定向能夠訪問服務器之外的資源 //4.重定向因爲請求屢次的,因此HttpServletRequest不是同一個對象,故不能使用它傳遞數據 }