黑马程序员技术交流社区
标题:
HELLO
[打印本页]
作者:
旺仔奶糖
时间:
2019-9-12 15:34
标题:
HELLO
@WebServlet("/loginServlet")
public class loginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String username=request.getParameter("username");
String password=request.getParameter("password");
String checkcode=request.getParameter("checkcode");
HttpSession session = request.getSession();
String checkCode_session = (String)session.getAttribute("checkCode_session");
session.removeAttribute("checkCode_session");
if(checkCode_session!=null&&checkCode_session.equalsIgnoreCase(checkcode)){
if("zhangsan".equals(username)){
session.setAttribute("user",username);
response.sendRedirect(request.getContextPath()+"/success.jsp");
}else{
request.setAttribute("login_error","用户名或者密码错误");
request.getRequestDispatcher("/login.jsp").forward(request,response);
}
}else{
request.setAttribute("cc_error","验证码错误");
request.getRequestDispatcher("/login.jsp").forward(request,response);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2