1. 程式人生 > 其它 >JAVAWEB學習筆記(三)

JAVAWEB學習筆記(三)

HttpServletRequest

  1. 獲取前端傳遞引數
    在這裡插入圖片描述

  2. 請求轉發

public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding(
"utf-8"); String username = req.getParameter("username"); String password = req.getParameter("password"); String[] hobbies = req.getParameterValues("hobbies"); System.out.println("=============="); System.out.
println(username); System.out.println(password); System.out.println(Arrays.toString(hobbies)); System.out.println("======================"); System.out.println(req.getContextPath()); req.getRequestDispatcher("/success.jsp").forward(req,resp)
; } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req,resp); } }