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(boolean create);

Source Link

Document

Returns the current <code>HttpSession</code> associated with this request or, if there is no current session and <code>create</code> is true, returns a new session.

Usage

From source file:br.com.manish.ahy.web.util.WebUtil.java

public static Object getSessionAttribute(HttpServletRequest req, String attribute) {
    HttpSession session = req.getSession(true);
    return session.getAttribute(attribute);
}

From source file:net.mindengine.oculus.frontend.web.Session.java

public static Session create(HttpServletRequest request) {
    return new Session(request.getSession(true));
}

From source file:com.sonicle.webtop.core.app.servlet.ServletHelper.java

/**
 * Retrieve the ID of the current http session.
 * @param request The http request//from ww  w. ja  v a  2  s.com
 * @return Session's ID
 */
public static String getSessionID(HttpServletRequest request) {
    HttpSession session = request.getSession(false);
    return getSessionID(session);
}

From source file:de.dominikschadow.javasecurity.csrf.CSRFTokenHandler.java

public static boolean isValid(HttpServletRequest request)
        throws ServletException, NoSuchAlgorithmException, NoSuchProviderException {
    if (request.getSession(false) == null) {
        throw new ServletException(MISSING_SESSION);
    }/*from w w  w.  j  a va  2 s.c om*/

    return StringUtils.equals(getToken(request.getSession(false)), request.getParameter(CSRF_TOKEN));
}

From source file:com.erudika.para.security.SecurityUtils.java

/**
 * Clears the session. Deletes cookies and clears the security context.
 * @param req HTTP request//from  w ww . j  a va2  s .  c o m
 */
public static void clearSession(HttpServletRequest req) {
    SecurityContextHolder.clearContext();
    if (req != null) {
        HttpSession session = req.getSession(false);
        if (session != null) {
            session.invalidate();
        }
    }
}

From source file:com.orig.gls.web.category.Categoryw.java

public static void handleGoCategory(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession(false);
    if ((String) session.getAttribute("uname") != null) {
        session.setAttribute("catfunc", request.getParameter("function"));
        session.setAttribute("categorytype", request.getParameter("categorytype"));
        session.setAttribute("content_page", "categories/mCategories_b.jsp");
    } else {/* ww  w  .jav  a 2 s.co  m*/
        session.setAttribute("content_page", "sessionexp.jsp");
    }
    response.sendRedirect("index.jsp");
}

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

/**
 * Get the current message from the session, and remove it from the session
 * so it won't be displayed again.// ww  w  .j  a v a  2  s.  co m
 * 
 * If there is no message, return the empty string.
 */
public static String getMessageAndClear(HttpServletRequest request) {
    if (request == null) {
        return NO_MESSAGE;
    } else {
        return getMessageAndClear(request.getSession(false));
    }
}

From source file:br.com.manish.ahy.web.util.WebUtil.java

public static void setSessionAttribute(HttpServletRequest req, String attribute, Object value) {
    log.debug("Setting session attribute: " + attribute + " - " + value);
    HttpSession session = req.getSession(true);
    session.setAttribute(attribute, value);
}

From source file:com.orig.gls.web.category.Categoryw.java

public static void handleMaintainCategory(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession(false);
    session.setAttribute("catadded", false);
    session.setAttribute("catexists", false);
    if ((String) session.getAttribute("uname") != null) {
        String function = request.getParameter("function");
        String categorytype = request.getParameter("categorytype");
        String categorycode = request.getParameter("categorycode");
        String categoryvalue = request.getParameter("categoryvalue");
        switch (function) {
        case "ADD":
            if (!Category.categoryExists(categorycode, categorytype)) {
                Category.addCategories(Bank.getBankId(), categorycode, categorytype, categoryvalue, new Date(),
                        (String) session.getAttribute("uname"), new Date(),
                        (String) session.getAttribute("uname"));
                session.setAttribute("catadded", true);
                session.setAttribute("content_page", "categories/mCategories_a.jsp");
            } else {
                session.setAttribute("catexists", true);
                session.setAttribute("content_page", "categories/mCategories_b.jsp");
            }//ww  w. j av a 2  s . c o m
            break;
        }
    } else {
        session.setAttribute("content_page", "sessionexp.jsp");
    }
    response.sendRedirect("index.jsp");
}

From source file:com.ultrapower.eoms.common.plugin.ecside.filter.ExportFilterUtils.java

public static Object getBean(HttpServletRequest request,String beanName){
   Object bean=null;//from  ww w .  jav  a2  s.  com
   ApplicationContext appContext=WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession(true).getServletContext());
   bean=appContext.getBean(beanName);
   if (bean==null){
      LogHandler.warnLog(logger,ECSideFilter.class," Can't find DataAccess Bean named "+beanName);
   }
   return bean;
}