用idea设计的一个学生管理系统,为什么在登录界面时候能注册成功,但是用这个账户登录就是突然账户密码清空,反正就是进不去里面
以下是loginservlet代码
package com.lili.servlet;
import com.alibaba.fastjson.JSON;
import com.lili.dao.impl.UserDaoImpl;
import com.lili.entity.User;
import com.lili.service.impl.UserServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("application/json");
PrintWriter out = response.getWriter();
String user = request.getParameter("username");
String passwd = request.getParameter("password");
List<User> userList = new ArrayList<>();
List<User> List = new UserServiceImpl(new UserDaoImpl()).findUser(user, passwd);
if (userList.size() > 0) {
// 添加进session
HttpSession session = request.getSession(true);
session.setAttribute("user", userList.get(0));
// 设置过期时间5分钟
session.setMaxInactiveInterval(60 * 5);
}
String str = JSON.toJSONString(userList);
out.write(str);
out.flush();
out.close();
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}