package zall.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;


public class ServletUtil {

    public static String getCookieValue(Cookie[] cookies, String name) {
        if( cookies == null )
            return null;

        for(Cookie cookie : cookies) {
            if (name.equals(cookie.getName()))
                return cookie.getValue();
        }
        return null;
    }

    // /mywebapp/servlet/MyServlet/a/b;c=123?d=789
    public static String getUrl(HttpServletRequest req) {
        String reqUri = req.getRequestURI();
        String queryString = req.getQueryString();   // d=789
        if (queryString != null) {
            reqUri += "?"+queryString;
        }
        return reqUri;
    }

}
