HttpServletRequest
客户端的请求,可以获得客户端的所有信息
1.获取前端参数的方法
@Override
protected void doPost(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(username+"-"+password+"-"+ Arrays.toString(hobbies));
System.out.println("===========");
System.out.println(req.getContextPath());
// 这里的/代表当前的项目目录,请求转发不用写/r,重定向要写
req.getRequestDispatcher("/success.jsp").forward(req, resp);
}
${pageContext.request.contextPath用来获取路径
<form action="${pageContext.request.contextPath}/login" method="post">
cookie和session
会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话。常用的会话跟踪技术是Cookie与Session。Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端记录信息确定用户身份。
cookie在客户端起作用,session在服务器端起作用
参考:https://www.cnblogs.com/l199616j/p/11195667.html#_label0_0