监听器
public class loginServlet extends HttpServlet{
//1.写出servlet
//2.配置访问路径
protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//设置编码方式
req.setCharacterEncoding("utf-8");
//获得数据
String name=req.getParameter("name");
String pwd=req.getParameter("pwd");
//逻辑处理
if("root".equals(name)&&"root123".equals(pwd)) {
//登录成功
req.getSession().setAttribute("islogin","");
resp.sendRedirect("index.jsp");
req.getSession().invalidate();
}else {
//登录失败
resp.sendRedirect("index.jsp");
}
}
}
过滤器