后台取瀏覽器中cookie的用法


private static View gsonView(String attributeName) {
        return gsonView(attributeName, null);
}
public static final String UTF8 = "UTF-8";
@RequestMapping(value = "/example01")
    public View example01(String cellNum, String passwd, Model model, HttpServletRequest request) {
        // Cookie取出用戶名,查詢此用戶的相關信息
        String username = "";
        Cookie[] cookies = request.getCookies();// 前端通過Ajax映射該.do方法,這樣便可以獲取瀏覽器傳過來的cookie信息
        String key = "";
        String value = "";
        for (Cookie cookie : cookies) {
            try {
                key = URLDecoder.decode(cookie.getName(), UTF8);
            } catch (UnsupportedEncodingException e) {
                LOG.error(e.getMessage());
            }
            try {
                value = URLDecoder.decode(cookie.getValue(), UTF8);
            } catch (UnsupportedEncodingException e) {
                LOG.error(e.getMessage());
            }
            if (key.equalsIgnoreCase(LOGONUSERIDLASTTIME)) {
                username = value;
                break;   //獲取到想要的信息后,break此for循環
            }
        }

        long id = sendSafeCmdOpt.getNextHistoryId();//取下一個id,此id通過創建數據庫sequence生成遞增的id long iD = 3000000000L + id;
        sendSafeCmdOpt.cellAlarm(username, iD, cellNum, passwd);
        boolean result = true;
        String attributeName = "cellAlarm";
        model.addAttribute(attributeName, result);//返回true,告訴前端Ajax,后台方法調用成功。 return gsonView(attributeName);//以gson方式返回true
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM