Example usage for javax.servlet.http HttpServletRequest getSession

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

Introduction

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

Prototype

public HttpSession getSession();

Source Link

Document

Returns the current session associated with this request, or if the request does not have a session, creates one.

Usage

From source file:org.openmrs.module.logmanager.web.util.WebUtils.java

/**
 * Gets an int parameter from the request that is being "remembered" in the session
 * @param request the http request/*from  w ww  .j a  v a  2  s.  c  o m*/
 * @param name the name of the parameter
 * @param def the default value of the parameter
 * @param sessionPrefix the prefix to generate session attribute from parameter name
 * @return the parameter value
 */
public static int getSessionedIntParameter(HttpServletRequest request, String name, int def,
        String sessionPrefix) {
    HttpSession session = request.getSession();
    int val = def;

    // If specified in request, read that and store in session
    if (request.getParameter(name) != null) {
        val = ServletRequestUtils.getIntParameter(request, name, def);
        session.setAttribute(sessionPrefix + name, val);
    }
    // Otherwise look for a matching attribute in the session
    else {
        Integer sessionVal = (Integer) session.getAttribute(sessionPrefix + name);
        if (sessionVal != null)
            val = sessionVal;
    }

    return val;
}

From source file:doc.action.SelectedDocsUtils.java

public static Collection saveSelectedDocsIDs(HttpServletRequest request) {
    //System.out.println("start");
    Collection documents = (Collection) request.getSession().getAttribute(Constant.SELECTED_PRESIDENTS);
    //System.out.println(documents);
    if (documents == null) {
        documents = new ArrayList();
        request.getSession().setAttribute(Constant.SELECTED_PRESIDENTS, documents);
    }/*from w w  w .  j av a  2s .c  o  m*/

    Enumeration parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameterName = (String) parameterNames.nextElement();
        if (parameterName.startsWith("chkbx_")) {
            String docId = StringUtils.substringAfter(parameterName, "chkbx_");
            String parameterValue = request.getParameter(parameterName);
            if (parameterValue.equals(Constant.SELECTED)) {
                if (!documents.contains(docId)) {
                    documents.add(docId);
                }
            } else {
                documents.remove(docId);
            }
        }
    }

    return documents;
}

From source file:edu.umich.its.lti.TcSiteToGoogleStorage.java

/**
 * Helper method to set the  value <site_id>,<user_id>,<user_email_address>,<google-folder-id> to the session 
 * @param request//from  ww  w . j  a  v  a 2s .  c om
 * @param linkedGoogleFolder
 */

private static void setSettingToSession(HttpServletRequest request, String linkedGoogleFolder) {
    request.getSession().setAttribute(GoogleLtiServlet.SETTING_SERVICE_VALUE_IN_SESSION, linkedGoogleFolder);
    M_log.debug("The value in the session while setting: " + linkedGoogleFolder);
}

From source file:com.fruit.core.util.IWebUtils.java

/**
 * ??/*from w w w  .j a  v  a 2 s. com*/
 * @author eason
 * @param request
 * @return
 */
public static SysUser getCurrentSysUser(HttpServletRequest request) {
    SysUser sysUser = getCurrentSysUser(request.getSession());
    if (sysUser == null) {
        String token = CookieUtils.getCookieByName(request, "token");
        if (CommonUtils.isNotEmpty(token)) {
            String[] tokenArray = new String(Base64.decodeBase64(token)).split(":");
            if (tokenArray.length == 3) {
                String expireTimeStr = tokenArray[1];
                if (new Date(Long.valueOf(expireTimeStr)).after(new Date())) {
                    String name = tokenArray[0];
                    String userInfo = tokenArray[2];
                    SysUser user = SysUser.me
                            .get(CommonUtils.getConditions(new Condition("name", Operators.EQ, name)));
                    if (user != null && user.getStatus().equals(1)) {
                        String userInfo2 = MD5Utils.GetMD5Code(
                                user.getName() + user.getPwd() + expireTimeStr + PropKit.get("app_key"));
                        if (userInfo2.equals(userInfo)) {
                            sysUser = user;
                            setCurrentLoginSysUserToSession(request.getSession(), sysUser);
                        }
                    }
                }
            }
            return sysUser;
        }
    }
    return sysUser;
}

From source file:com.quartz.monitor.util.Tools.java

public static QuartzInstance getQuartzInstance() {

    HttpServletRequest request = ServletActionContext.getRequest();// request
    HttpSession session = request.getSession();// requestsession
    String uuid = (String) session.getAttribute("configId");
    Map<String, QuartzInstance> quartzInstanceMap = QuartzInstanceContainer.getQuartzInstanceMap();
    if (quartzInstanceMap == null || quartzInstanceMap.size() == 0 || uuid == null || uuid.equals("")) {
        return null;
    }/*ww w  . j  a v  a 2 s.c o m*/
    QuartzInstance instance = quartzInstanceMap.get(uuid);

    if (instance == null) {
        try {
            new InitAction().execute();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        instance = Tools.getQuartzInstance();
    }
    return instance;
}

From source file:com.acc.filter.FilterSpringUtil.java

/**
 * Returns the Spring bean with name <code>beanName</code> and of type <code>beanClass</code>. If no bean could be
 * resolved for the specified name, the bean is looked up using type.
 * /*from  www . j a v  a 2s .  c  o  m*/
 * @param <T>
 *           type of the bean
 * @param httpRequest
 *           the http request
 * @param beanName
 *           name of the bean or <code>null</code> if it should be automatically resolved using type
 * @param beanClass
 *           expected type of the bean
 * @return the bean matching the given arguments or <code>null</code> if no bean could be resolved
 * 
 */
public static <T> T getSpringBean(final HttpServletRequest httpRequest, final String beanName,
        final Class<T> beanClass) {
    final HttpSession session = httpRequest.getSession();
    final ServletContext servletContext = session.getServletContext();
    return getSpringBean(servletContext, beanName, beanClass);
}

From source file:com.aistor.common.servlet.ValidateCodeServlet.java

public static boolean validate(HttpServletRequest request, String validateCode) {
    String code = (String) request.getSession().getAttribute("validateCode");
    return validateCode.toUpperCase().equals(code);
}

From source file:edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties.java

public static ConfigurationProperties getBean(ServletRequest request) {
    if (request == null) {
        throw new NullPointerException("request may not be null.");
    }//from w w  w. j a v a 2s.  c o m
    if (!(request instanceof HttpServletRequest)) {
        throw new IllegalArgumentException("request must be an HttpServletRequest");
    }
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    return getBean(httpRequest.getSession());
}

From source file:com.eryansky.common.web.servlet.ValidateCodeServlet.java

/**
 * ?./*from   w ww . j  a  v  a  2s  . c o  m*/
 */
public static boolean validate(HttpServletRequest request, String validateCode) {
    String code = (String) request.getSession().getAttribute(SysConstants.SESSION_VALIDATE_CODE);
    return validateCode.toUpperCase().equalsIgnoreCase(code);
}

From source file:apm.common.servlet.ValidateCodeServlet.java

public static boolean validate(HttpServletRequest request, String validateCode) {
    String code = (String) request.getSession().getAttribute(VALIDATE_CODE);
    return validateCode.toUpperCase().equals(code);
}