Session

@WebServlet({ "/someServlet", "/some" })

public class someServlet extends HttpServlet {

protected void service(HttpServletRequest request, HttpServletResponse response

throws ServletException, IOException {

response.setContentType("text/html;charset=utf-8");

PrintWriter out = response.getWriter(); 

HttpSession session = request.getSession();

String sessionId = session.getId();

System.out.println(sessionId);

Integer count = (Integer) session.getAttribute("count");

if(count==null){

count=1;

}else{

count++;

}

session.setAttribute("count", count);

out.println("你是第:"+count+"次访问");

out.close();

}


}

你可能感兴趣的:(session,java)