public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
OutputStream out=response.getOutputStream();
response.setCharacterEncoding("UTF-8");
Cookie[] cook=request.getCookies();
if(cook==null)
{
out.write("第一次访问,welcome".getBytes("UTF-8"));
}
else
{
for(int i=0;i<cook.length;++i)
{
if(cook[i].getName().equals("lasttime"))
{
long time=Long.parseLong(cook[i].getValue());
out.write(("上次访问时间:"+new Date(time).toLocaleString()).getBytes("UTF-8"));
}
}
}
Cookie cookie=new Cookie("lasttime",(System.currentTimeMillis())+"");
cookie.setMaxAge(3600);
cookie.setPath("/myweb/servlet/ServletDem