//獲取request請求中所有參數
Enumeration<String> names = request.getParameterNames(); HashMap<String, Object> params = new HashMap<String, Object>(); while (names.hasMoreElements()) { String name = names.nextElement(); params.put(name, request.getParameter(name).trim()); }
//獲取用戶登錄信息
String token = request.getParameter("token"); // UserEntityDFG userEntityDFG = (UserEntityDFG) SessionHelper.get(token+"a");//用於添加補充信息 UserEntity userEntity = (UserEntity) SessionHelper.get(token); //UserEntity userEntity=userEntityDFG.getUserEntity();
//當前登錄用戶名 params.put("USERNAME", userEntity.getUserName());
//當前登錄用戶ID params.put("USERID", userEntity.getUserID()); params.put("ORGID", userEntity.getOrgID());
當前登錄用戶名,用戶ID。
針對不同項目情況,UesrEntity大體會有差別,但是類似。
-------------------------------------------------------------------------------------------------------------------------------------------------------
Session與Cookie的區別
Session與Cookie都是解決Http協議的無狀態問題,但是兩者之間還是存在一定區別的:
- Cookie數據存儲在客戶端的瀏覽器內存中或本地緩存文件中,Session數據存儲在服務器端的內存中。
- Cookie數據存儲安全性較低,Session數據存儲安全性較高。
- Session數據存儲在服務器端內存中,訪問增多時,降低服務器端性能。而Cookie則不會對服務器端性能造成影響。
- 單個Cookie存儲的數據最大是4KB,一個網站只能存儲20個Cookie。Session則沒有這個問題。
- Session在關閉瀏覽器時失效,而持久Cookie則可以存儲更長有效時間。
總的來說,Session與Cookie各有優勢,不能簡單來說誰更優。具體用法要考慮具體案例情況而定。