1.jsp
<%
String name="";
String pwd="";
Cookie[] cook=request.getCookies();
if(cookie!=null)
{
for(int i=0;i<cook.length;i++)
{
if(cook[i].getName().equals("myCookieName"))
{
name=cook[i].getValue();
}
if(cook[i].getName().equals("myCookiePwd"))
{
pwd=cook[i].getValue();
}
}
}
%>
<form name="postion_login_from" action="UserServlet" method="post">
<table>
<tr><td class="comm">用户名:</td>
<td><input type="text" name="pname" value="<%=name%>">
</td>
</tr>
<tr><td class="comm">密码:</td>
<td><input type="text" name="pwd" value="<%=pwd%>" >
</td>
</tr>
</table>
</form>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
2.servlet
Cookie myCookieName=new Cookie("myCookieName",uname); myCookieName.setMaxAge(1*24*60*60); response.addCookie(myCookieName);
Cookie myCookiePwd=new Cookie("myCookiePwd",upwd); myCookiePwd.setMaxAge(1*24*60*60);