Example usage for javax.servlet.http HttpServletRequest getAttribute

List of usage examples for javax.servlet.http HttpServletRequest getAttribute

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getAttribute.

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Usage

From source file:mojo.view.util.DebugUtils.java

@SuppressWarnings("rawtypes")
public static void logRequestAttributes(HttpServletRequest req) {
    logger.debug("REQUEST ATTRIBUTES");
    logger.debug("------------------");

    Enumeration enums = req.getAttributeNames();

    while (enums.hasMoreElements()) {
        String attrName = (String) enums.nextElement();
        Object attrValue = req.getAttribute(attrName);
        StringBuilder sb = new StringBuilder();
        sb.append(attrName + ": " + attrValue);
        logger.debug(sb.toString());//from w  w w .  j  a  v  a2s .  co  m
    }

    logger.debug("");
}

From source file:com.toft.widgets.login.LoginAction.java

/**
 * ????/* w  w w .j av  a 2s.c  om*/
 * 
 * @param request
 * @return string:???
 */
private static String getPublicKeySerialNumber(HttpServletRequest request) {
    X509Certificate[] chain = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");
    if (chain != null) {
        X509Certificate cert = chain[0];
        String certSerialNumber = cert.getSerialNumber().toString(16);
        //         certSerialNumber = org.apache.commons.lang.StringUtils.leftPad(certSerialNumber, (certSerialNumber.length()+1)/2*2, '0');
        return certSerialNumber;
    }
    return null;
}

From source file:com.log4ic.compressor.utils.HttpUtils.java

/**
 * ?/*from   ww w .ja va  2  s . co  m*/
 *
 * @param request
 * @return
 */
public static String getQueryString(HttpServletRequest request) {
    //?JSP?include?
    Object queryString = request.getAttribute("javax.servlet.include.query_string");
    if (queryString == null) {
        //?JSP?forward?
        queryString = request.getAttribute("javax.servlet.forward.query_string");
    }

    if (queryString != null) {
        return queryString.toString();
    }
    return request.getQueryString();
}

From source file:net.sourceforge.vulcan.web.JstlFunctions.java

@SuppressWarnings("unchecked")
public static List<String> getActionErrorPropertyList(HttpServletRequest request) {
    final List<String> errorList = new ArrayList<String>();

    final ActionMessages errors = (ActionMessages) request.getAttribute(Globals.ERROR_KEY);
    if (errors != null) {
        Iterator<String> itr = errors.properties();
        while (itr.hasNext()) {
            errorList.add(itr.next());/*from  w  w  w.  j  a  v a 2 s  .  com*/
        }
    }

    return errorList;
}

From source file:com.log4ic.compressor.utils.HttpUtils.java

/**
 * ??/*from  www.  jav  a  2s  . co  m*/
 *
 * @param request
 * @return
 */
public static String getRequestUri(HttpServletRequest request) {
    //?JSP?include??
    Object queryUri = request.getAttribute("javax.servlet.include.request_uri");
    if (queryUri == null) {
        //?JSP?forward??
        queryUri = request.getAttribute("javax.servlet.forward.request_uri");
    }

    if (queryUri != null) {
        return queryUri.toString();
    }
    return request.getRequestURI();
}

From source file:eionet.util.SecurityUtil.java

/**
 *
 * @param request/* ww w  .  j  a v  a 2 s. c o  m*/
 * @return
 */
public static String buildAfterLoginURL(HttpServletRequest request) {

    String requestUri = (String) request.getAttribute("javax.servlet.forward.request_uri");
    if (requestUri == null) {
        requestUri = request.getRequestURL().toString();
    }

    String queryString = (String) request.getAttribute("javax.servlet.forward.query_string");
    if (queryString == null) {
        queryString = request.getQueryString();
    }

    return queryString == null ? requestUri : requestUri + "?" + queryString;
}

From source file:com.leixl.easyframework.web.TplUtils.java

/**
 * ????//www  . jav a2s .c  om
 * 
 * @param request
 * @param model
 */
public static void frontData(HttpServletRequest request, Map<String, Object> map) {
    String location = RequestUtils.getLocation(request);
    Long startTime = (Long) request.getAttribute(START_TIME);
    frontData(map, location, startTime);
}

From source file:com.activecq.api.utils.HttpRequestUtil.java

/**
 * <p>//  w  w w  .j  a v  a 2s  .c  om
 * Gets the Attribute or Parameter value from the Request.
 * </p><p>
 * Attribute takes precedence
 * </p><p>
 * If neither an Attribute or Parameter value exists @ key, return the dfault
 * </p>
 *
 * @param request
 * @param key
 * @param dfault
 * @return
 */
public static String getAttributeOrParameter(HttpServletRequest request, String key, String dfault) {
    String value = null;
    if (request == null) {
        return value;
    }

    if (hasAttribute(request, key)) {
        value = (String) request.getAttribute(key);
    } else if (hasParameter(request, key)) {
        value = request.getParameter(key);
    }

    if (StringUtils.isBlank(value)) {
        value = dfault;
    }

    return value;
}

From source file:com.redhat.rhn.frontend.action.LoginHelper.java

private static Set<String> getExtGroups(HttpServletRequest requestIn) {
    Set<String> extGroups = new HashSet<String>();
    Long nGroups = null;//from w  ww  . ja v a  2 s. co m
    String nGroupsStr = (String) requestIn.getAttribute("REMOTE_USER_GROUP_N");
    if (nGroupsStr != null) {
        try {
            nGroups = Long.parseLong(nGroupsStr);
        } catch (NumberFormatException nfe) {
            // do nothing, nGroups stays null
        }
    }
    if (nGroups == null) {
        log.warn("REMOTE_USER_GROUP_N not set!");
        return extGroups;
    }
    for (int i = 1; i <= nGroups; i++) {
        String extGroupName = (String) requestIn.getAttribute("REMOTE_USER_GROUP_" + i);
        if (extGroupName == null) {
            log.warn("REMOTE_USER_GROUP_" + i + " not set!");
            continue;
        }
        extGroups.add(extGroupName);

    }
    return extGroups;
}

From source file:com.adito.core.actions.AbstractMultiFormDispatchAction.java

private static ActionForm getActionForm(ActionMapping subMapping, HttpServletRequest request) {
    String formName = subMapping.getName();
    if ("request".equals(subMapping.getScope()))
        return (ActionForm) request.getAttribute(formName);
    else/*from   www .j  ava  2 s . com*/
        return (ActionForm) request.getSession().getAttribute(formName);
}