//login.jsp<%@ page language="java" import="java.util.,java.net." contentType="text/html; charset=ut
//login.jsp
<%@ page language="java" import="java.util.,java.net." contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body> <% request.setCharacterEncoding("utf-8"); String username=""; String password=""; Cookie cookies[]=request.getCookies();
if(cookies!=null&&cookies.length>0){ for(Cookie c:cookies){ if(c.getName().equals("username")){ username=URLDecoder.decode(c.getValue(),"utf-8");//解码方法 } if(c.getName().equals("password")){ password=URLDecoder.decode(c.getValue(),"utf-8"); } } }%> <hr><center><br><br><br><br><br><br><br> <form action="dologin.jsp" method="post" name="fom1"> <table> <tr> <td>用户名:</td> <td><input type="text" name="username" value=<%=username%>></td> </tr> <tr> <td>密码:</td> <td><input type="password" name="password" value="<%=password%>"></td> </tr> <tr> <td colspan="2"><input type="checkbox" name="isCook" value="" checked="checked">记住密码</td> </tr> <tr> <td><input type="submit" name="su" value="提交"></td> <td><input type="reset" name="re" value="重置"></td> </tr> </table> </form> </center>
</body></html>
<%@page import="java.net.URLEncoder"%><%@ page language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body><% request.setCharacterEncoding("utf-8"); String cookies[]=request.getParameterValues("isCook"); if(cookies!=null&&cookies.length>0){ String username=URLEncoder.encode(request.getParameter("username"),"utf-8");//加码方法 String password=URLEncoder.encode(request.getParameter("password"),"utf-8");
Cookie usernameCookie=new Cookie("username",username); Cookie passwordCookie=new Cookie("password",password); usernameCookie.setMaxAge(864000); passwordCookie.setMaxAge(864000); response.addCookie(usernameCookie); response.addCookie(passwordCookie);
}else{Cookie cook[]=request.getCookies();if(cook!=null&&cook.length>0){for(Cookie c:cook){if(c.getName().equals("username")||c.getName().equals("password")){c.setMaxAge(0);response.addCookie(c);}}}
}
%>
<div>登录成功</div></body></html>