⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cookiesmgr.java

📁 java阿里巴巴代码
💻 JAVA
字号:
package com.saas.biz.commen;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.saas.biz.serverMgr.ServerInfo;
import com.saas.sys.log.Logger;

public class cookiesMgr implements Filter{
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        //try 
        //{	
        		Logger log = new Logger(this);
		    		HttpServletRequest request = (HttpServletRequest) req;
		    		HttpSession session = request.getSession(true);
		    		Cookie[] cookies;
		    		cookies = request.getCookies();
		    		if (cookies != null && cookies.length > 1) 
		    		{
		    			String session_user_id = getCookieValue(cookies, "SESSION_USER_ID");
		    			String session_cust_id = getCookieValue(cookies, "SESSION_CUST_ID");
		    			String session_user_name = getCookieValue(cookies, "SESSION_USER_NAME");
		    			String session_cust_name = getCookieValue(cookies, "SESSION_CUST_NAME");
		    			String session_cust_class = getCookieValue(cookies, "SESSION_CUST_CLASS");
		    			String session_depart_code = getCookieValue(cookies, "DEPART_CODE");
		    			String session_role_code = getCookieValue(cookies,"SESSION_ROLE_CODE");
		    			String session_user_type = getCookieValue(cookies,"SESSION_USER_TYPE");
		    			
		    			session.setAttribute("SESSION_USER_ID", session_user_id);
		    			session.setAttribute("SESSION_CUST_ID", session_cust_id);
		    			session.setAttribute("SESSION_USER_NAME", session_user_name);
		    			session.setAttribute("SESSION_CUST_NAME", session_cust_name);
		    			session.setAttribute("SESSION_CUST_CLASS", session_cust_class);
		    			session.setAttribute("DEPART_CODE", session_depart_code);
		    			session.setAttribute("SESSION_ROLE_CODE", session_role_code);
		    			session.setAttribute("SESSION_USER_TYPE", session_user_type);
    				}
    		 		chain.doFilter(req, resp);
				//}
        //catch (Exception e) 
        //{
				//	throw new RuntimeException(e);
        //}
	}

	public String getCookieValue(Cookie[] cookies, String name) {
		String value = "";

		if (cookies == null) {
			value = "";
		}
		else {
			for (int i = 0; i < cookies.length; i++) {
				if (name.equalsIgnoreCase(cookies[i].getName())) {
					value = cookies[i].getValue();
					return value;
				}
			}
		}
		return value;
	}

	public void init(FilterConfig config) throws ServletException {}

	public void destroy() {}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -