response
总结:1.转发是一次请求,重定向是两次2.转发不会改变url,重定向会改变3.请求转发是在服务器内部完成的,而重定向是在客户端完成的4.转发的url必须是当前web工程内部的地址,重定向可以是任意地址
获取前端传递参数(request应用代码未运行成功)
点击查看代码
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("========================");
// 通过请求转发
req.getRequestDispatcher(req.getContextPath()+"/success.jsp").forward(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}