<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");//解决中文乱码的问题
String name = request.getParameter("username");
String password = request.getParameter("password");
session.setAttribute("name", name);
Cookie cookie = new Cookie("name",name);
cookie.setMaxAge(300); //设置cookie有效期为30s
response.addCookie(cookie);
if(name.equals(password))
{%>
<h1>用户登录成功两秒后为您跳转</h1>
<%
response.setHeader("refresh", "2;url=index.jsp");
}
else{%>
<h1>用户登录失败两秒后跳转请重新登录</h1>
<% response.setHeader("refresh", "2;url=login.jsp");
}
%>
</body>
</html>