这是我的servlet代码..我正在尝试添加cookie,但它没有按照我的方式进行。任何人都可以解决它吗?

时间:2019-05-24 07:32:22

标签: servlets cookies

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String user_name = request.getParameter("user_name");
    String password = request.getParameter("password");
    System.out.println(user_name+" "+password);
    Cookie unCk = null;

    boolean isCredRight = User_CRUD.isCredRight(user_name,password);

    HttpSession session = request.getSession(true);
    RequestDispatcher rd= null;

    if (isCredRight) {
        unCk = new Cookie("username",user_name);
        response.addCookie(unCk);
        response.sendRedirect("PMT_Welcome_Admin.jsp");
    } else {
        request.setAttribute("credError","<font color='red'>Invalid Username or Password</font>");
        rd = request.getRequestDispatcher("PMT_Login_Admin.jsp");
        rd.forward(request, response);
    }
}

0 个答案:

没有答案