效果图:
代码:
logon.jsp:
<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@ 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>
<%
Cookie[] cookies = request.getCookies();
if(cookies != null){
for(Cookie cookie:cookies){
if("username".equals(cookie.getName())){
pageContext.setAttribute("username", cookie.getValue());
}
}
}
%>
</head>
<body>
<form action="/logon" method="post">
用户名:<input type="text" name="username" value="${username }"/><br/>
记住我:<input type="checkbox" name="rem" ${empty username?'':'checked' }/><br/>
<input type="submit" value="登录"/>
</form>
</body>
</html>
LogonServlet.java:
package text.cookie