zoukankan      html  css  js  c++  java
  • 重定向和请求转发

    重定向

    重定向的路径名需要写项目名(路径名需要写完整)

    重定向是HttpServletResponse对象的方法。

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            String username=req.getParameter("username");
            String password=req.getParameter("password");
            System.out.println(username+":"+password);
            //重定向
            resp.sendRedirect("/r/success.jsp");
        }

    请求转发

    转发的路径名不需要写项目名(只需要写页面名字即可)

    请求转发是HttpServletRequest的方法

      @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            req.setCharacterEncoding("utf-8");
            String username=req.getParameter("username");
            String password=req.getParameter("password");
            String[] hobbys=req.getParameterValues("hobbys");
            System.out.println("=================================");
            System.out.println(username);
            System.out.println(password);
            System.out.println(Arrays.toString(hobbys));
            System.out.println("=================================");
    //   请求转发
            req.getRequestDispatcher("/success.jsp").forward(req,resp);
            resp.setCharacterEncoding("utf-8");
        }//
  • 相关阅读:
    Codeforces 841 D
    Codeforces 838 B
    Codeforces 833 C
    Codeforces 101572 D
    Codeforces 101173 C
    Codeforces 444 C
    POJ 3076 Sudoku
    Codeforces 1025 D
    算法笔记--基环树
    Codeforces 1016 E
  • 原文地址:https://www.cnblogs.com/huangui/p/12787273.html
Copyright © 2011-2022 走看看