JAVAWEB學習筆記(三)
阿新 • • 發佈:2021-01-19
HttpServletRequest
-
獲取前端傳遞引數
-
請求轉發
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);
}
}