下边的是form代码
登录
用户名
密码
登录
下边是后台servelet代码
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
String action = request.getParameter("action");
//这的action就能取到值
if(action.equals("login")){
String username = request.getParameter("username");
String password = request.getParameter("password");
//这的username和password就取不到值,为什么啊?
User u = userservice.login(username, password);
if(u!=null){
if(u.getIsDelete()==0){
request.getSession().setAttribute("user", u);
response.sendRedirect("user?action=index");
}else{
request.getSession().setAttribute("userIsDeleMsg", "该用户已被禁用,无法登录!");
request.getRequestDispatcher("login.jsp").forward(request, response);
}
}else {
request.getSession().setAttribute("msg", "验证失败,请重新输入用户名或密码!");
response.sendRedirect("Login.jsp");
}
}else if(action.equals("index")){
//跳转到首页
request.getRequestDispatcher("/index.jsp").forward(request, response);
}
}