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:edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsFirstTimeExternalPage.java

/**
 * Let some other request set the External Auth ID and the afterLogin URL
 * before redirecting to here./*from w w  w .j ava2  s  . c o m*/
 */
public static void setExternalLoginInfo(HttpServletRequest req, String externalAuthId, String afterLoginUrl) {
    req.getSession().setAttribute(ATTRIBUTE_EXTERNAL_LOGIN_INFO,
            new ExternalLoginInfo(externalAuthId, afterLoginUrl));
}

From source file:edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.java

static OrcidConfirmationState fetch(HttpServletRequest req) {
    HttpSession session = req.getSession();
    Object o = session.getAttribute(ATTRIBUTE_NAME);
    if (o instanceof OrcidConfirmationState) {
        return (OrcidConfirmationState) o;
    } else {//from  ww  w . j  a v a  2  s . co  m
        OrcidConfirmationState ocs = new OrcidConfirmationState();
        session.setAttribute(ATTRIBUTE_NAME, ocs);
        return ocs;
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration.java

/**
 * Get the bean from the context. If there no bean, create one on the fly
 * and store it in the context.//w w w .  j a  va  2s  .  co  m
 * 
 * Never returns null.
 */
public static SelfEditingConfiguration getBean(ServletRequest request) {
    if (request == null) {
        log.error("Request is null");
        return new SelfEditingConfiguration(null);
    }

    if (!(request instanceof HttpServletRequest)) {
        log.error("Not an HttpServletRequest: " + request.getClass());
        return new SelfEditingConfiguration(null);
    }
    HttpServletRequest hreq = (HttpServletRequest) request;

    return getBean(hreq.getSession().getServletContext());
}

From source file:com.bsb.cms.moss.commons.tag.IfAuthButtonTag.java

/**
 * ???/*from ww w.j  a  v a  2 s.c  om*/
 * 
 * @param req
 * @param code ??
 * @return true:
 */
public static boolean isHasOperate(HttpServletRequest req, String code) {
    boolean isHasOperate = false;
    if (MossActionUtils.isAdmin(req.getSession())) {
        isHasOperate = true;
    } else {
        User user = MossActionUtils.getUser(req.getSession());
        List<SysModelDTO> menus = user.getMenus();
        if (CollectionUtils.isNotEmpty(menus)) {
            for (SysModelDTO menu : menus) {
                if (code.equals(menu.getModelCode())) {
                    isHasOperate = true;
                    break;
                }
            }
        }
    }
    return isHasOperate;
}

From source file:com.bluexml.side.Framework.alfresco.shareLanguagePicker.CustomDispatcherServlet.java

public static void setLanguageFromLayoutParam(HttpServletRequest req) {
    String urlLang = req.getParameter("shareLang");
    HttpSession currentSession = req.getSession();
    String sessionLang = (String) currentSession.getAttribute("shareLang");

    //1st option: Select the url param shareLang
    if (urlLang != null) {
        I18NUtil.setLocale(I18NUtil.parseLocale(urlLang));
        currentSession.setAttribute("shareLang", urlLang);
    } else if (sessionLang != null) {
        I18NUtil.setLocale(I18NUtil.parseLocale(sessionLang));
    } else {/*from   w  w w .  j ava  2 s . c o  m*/
        // set language locale from browser header
        String acceptLang = req.getHeader("Accept-Language");
        if (acceptLang != null && acceptLang.length() != 0) {
            StringTokenizer t = new StringTokenizer(acceptLang, ",; ");
            // get language and convert to java locale format
            String language = t.nextToken().replace('-', '_');
            I18NUtil.setLocale(I18NUtil.parseLocale(language));
        }
    }
}

From source file:com.formkiq.core.webflow.FlowManager.java

/**
 * Finish Flow.//  w  ww . ja  v  a 2 s .c  om
 * @param request {@link HttpServletRequest}
 */
public static void finish(final HttpServletRequest request) {

    WebFlow flow = getCurrentWebFlow(request);
    request.getSession().removeAttribute(getExecutionSessionKey(flow.getSessionKey()).getLeft());
}

From source file:edu.cornell.mannlib.vitro.webapp.email.FreemarkerEmailFactory.java

private static FreemarkerEmailFactory getFactory(HttpServletRequest req) {
    ServletContext ctx = req.getSession().getServletContext();
    return (FreemarkerEmailFactory) ctx.getAttribute(ATTRIBUTE_NAME);
}

From source file:com.chinarewards.gwt.license.util.FileUploadServlet.java

/**
 * @param uploadRootName/*from  ww  w .  j  ava2s .c om*/
 *            
 * 
 * */
private static String getUploadPath(HttpServletRequest request, String uploadRootName) {
    String realPath = request.getSession().getServletContext().getRealPath("/");
    String uploadPath = null;
    // System.out.println("============realPath:" + realPath);
    int rootIndex = realPath.indexOf("jboss-5.1.0.GA");
    if (rootIndex < 0) {
        rootIndex = realPath.indexOf("war");
    }

    if (rootIndex < 0) {
        return null;
    } else {
        realPath = realPath.substring(0, rootIndex);

        uploadPath = realPath + uploadRootName;
        // System.out.println("============uploadPath:" + uploadPath);
        File myFilePath = new File(uploadPath);
        if (!myFilePath.exists()) {
            myFilePath.mkdir();
            System.out.println("" + myFilePath);
        }
    }
    return uploadPath;
}

From source file:com.netsteadfast.greenstep.util.SystemFormUtils.java

public static void writePage(SysFormTemplateVO template, HttpServletRequest request) throws Exception {
    String pageFileFullPath = request.getSession().getServletContext().getRealPath("/");
    pageFileFullPath += FORM_PAGE_PATH + template.getFileName();
    if (!FSUtils.writeStr2(pageFileFullPath, new String(template.getContent(), Constants.BASE_ENCODING))) {
        throw new Exception("create page file error.");
    }//  w w  w .  j a v  a 2s  . c  om
    logger.info("write template file: " + pageFileFullPath);
}

From source file:com.netsteadfast.greenstep.util.SystemFormUtils.java

public static void writePage2(TbSysFormTemplate template, HttpServletRequest request) throws Exception {
    String pageFileFullPath = request.getSession().getServletContext().getRealPath("/");
    pageFileFullPath += FORM_PAGE_PATH + template.getFileName();
    if (!FSUtils.writeStr2(pageFileFullPath, new String(template.getContent(), Constants.BASE_ENCODING))) {
        throw new Exception("create page file error.");
    }//from w w w .j  a  v a 2  s  . c  o  m
    logger.info("write template file: " + pageFileFullPath);
}