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不是同一个对象,故不能使用它传递数据 }