session的增加读取

1 session.setAttribute("username", "张三");
2 String u = (String) session.getAttribute("username");

 

 

application(服务器级别的,如果服务关了/或断电了,那么他就会消失)

1 List onlineUserList = (List)  application.getAttribute("onlineUserList");
2 if(onlineUserList == null)
3 {
4      onlineUserList = new ArrayList();
5    application.setAttribute("onlineUserList", onlineUserList);
6 }
7 onlineUserList.add("张三");