Example usage for javax.servlet.http HttpSession getAttribute

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

Introduction

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

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the object bound with the specified name in this session, or null if no object is bound under the name.

Usage

From source file:com.acc.storefront.filters.StorefrontFilter.java

protected boolean isSessionInitialized(final HttpSession session) {
    return session.getAttribute(this.getClass().getName()) != null;
}

From source file:miage.ecom.web.controller.CartController.java

@RequestMapping(value = "/cart/add", method = RequestMethod.POST)
public String addProductToCart(@RequestParam(value = "idProduct") Integer productId,
        @RequestParam(value = "quantity") Integer quantity, HttpSession session) {

    CartBean cart;//from  w w w  . j  a  va  2s . co  m
    if (session.getAttribute("cart") == null) {
        cart = new CartBean();
    } else {
        cart = (CartBean) session.getAttribute("cart");
    }
    ecomBeanFrontLocal.addProductToCart(cart, productId, quantity);
    session.setAttribute("cart", cart);
    return "redirect:/cart";
}

From source file:net.groupbuy.service.impl.RSAServiceImpl.java

@Transactional(readOnly = true)
public String decryptParameter(String name, HttpServletRequest request) {
    Assert.notNull(request);/*from  www .  ja  v a  2  s.c o m*/
    if (name != null) {
        HttpSession session = request.getSession();
        RSAPrivateKey privateKey = (RSAPrivateKey) session.getAttribute(PRIVATE_KEY_ATTRIBUTE_NAME);
        String parameter = request.getParameter(name);
        if (privateKey != null && StringUtils.isNotEmpty(parameter)) {
            return RSAUtils.decrypt(privateKey, parameter);
        }
    }
    return null;
}

From source file:org.ratty.impl.SecurityServiceImpl.java

public void haveToBeLogged() throws NotLoggedException {

    ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    HttpSession session = attr.getRequest().getSession();

    if (session != null) {
        Object isLoggedObj = session.getAttribute("isLogged");

        if (!(isLoggedObj != null && isLoggedObj instanceof Boolean && (Boolean) isLoggedObj)) {
            throw new NotLoggedException("The user is not logged !");
        }/* w  ww .j  a  v  a  2 s . c  om*/
    }
}

From source file:pivotal.au.se.gemfirexdweb.controller.HistoryController.java

@RequestMapping(value = "/history", method = RequestMethod.GET)
public String showHistory(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/*w  w w  .j  av a  2  s  .  c  om*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to show command history");
    UserPref userPref = (UserPref) session.getAttribute("prefs");

    String histAction = request.getParameter("histAction");

    if (histAction != null) {
        logger.debug("histAction = " + histAction);
        // clear history
        session.setAttribute("history", new LinkedList());

        model.addAttribute("historyremoved", "Succesfully cleared history list");
    }

    LinkedList historyList = (LinkedList) session.getAttribute("history");

    int maxsize = userPref.getHistorySize();

    model.addAttribute("historyList", historyList.toArray());
    model.addAttribute("historysize", historyList.size());

    // This will resolve to /WEB-INF/jsp/history.jsp
    return "history";
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    HttpSession session = req.getSession();

    Integer count = (Integer) session.getAttribute("snoop.count");
    if (count == null)
        count = new Integer(1);
    else//www . j a va 2s  .c  om
        count = new Integer(count.intValue() + 1);
    session.setAttribute("snoop.count", count);

    out.println("<HTML><HEAD><TITLE>SessionSnoop</TITLE></HEAD>");
    out.println("<BODY><H1>Session Snoop</H1>");

    out.println("You've visited this page " + count + ((count.intValue() == 1) ? " time." : " times."));

    out.println("<P>");

    out.println("<H3>Here is your saved session data:</H3>");
    Enumeration e = session.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        out.println(name + ": " + session.getAttribute(name) + "<BR>");
    }

    out.println("<H3>Here are some vital stats on your session:</H3>");
    out.println("Session id: " + session.getId() + " <I>(keep it secret)</I><BR>");
    out.println("New session: " + session.isNew() + "<BR>");
    out.println("Timeout: " + session.getMaxInactiveInterval());
    out.println("<I>(" + session.getMaxInactiveInterval() / 60 + " minutes)</I><BR>");
    out.println("Creation time: " + session.getCreationTime());
    out.println("<I>(" + new Date(session.getCreationTime()) + ")</I><BR>");
    out.println("Last access time: " + session.getLastAccessedTime());
    out.println("<I>(" + new Date(session.getLastAccessedTime()) + ")</I><BR>");

    out.println("Requested session ID from cookie: " + req.isRequestedSessionIdFromCookie() + "<BR>");
    out.println("Requested session ID from URL: " + req.isRequestedSessionIdFromURL() + "<BR>");
    out.println("Requested session ID valid: " + req.isRequestedSessionIdValid() + "<BR>");

    out.println("<H3>Test URL Rewriting</H3>");
    out.println("Click <A HREF=\"" + res.encodeURL(req.getRequestURI()) + "\">here</A>");
    out.println("to test that session tracking works via URL");
    out.println("rewriting even when cookies aren't supported.");

    out.println("</BODY></HTML>");
}

From source file:com.kalai.controller.AjaxCallController.java

@RequestMapping("/ajaxcall")
public String ajax(HttpSession logsession) {
    String username = "";
    username = (String) logsession.getAttribute("username");
    if (username != null && username.trim().length() != 0) {
        return "ajaxcall";
    } else {/*  ww  w .  ja va2  s . c om*/
        return "index";
    }
}

From source file:com.kalai.controller.HomeController.java

@RequestMapping(value = "/home")
public String home(HttpSession session, ModelMap map) {
    String username = "";
    try {//from   w  ww .jav a 2s  .co  m
        username = (String) session.getAttribute("username");
        if (!username.equals("") && username.trim().length() != 0) {
            map.addAttribute("msg", "Hai this is home page using Spring and Hibernate=====" + username);
            return "Home";
        } else {
            return "PageNotFound";
        }
    } catch (Exception ex) {
        return "PageNotFound";
    }

}

From source file:com.kalai.controller.UserListController.java

@RequestMapping("/userlist")
public String userlist(ModelMap map, HttpSession ses) {
    String user = "";
    try {/*  w  w w  .  j  a v  a2s .c  o  m*/
        user = (String) ses.getAttribute("username");
        if (user != null && !user.equals("") && user.trim().length() != 0) {
            session = HibernateUtil.getSessionFactory().openSession();
            session.getTransaction().begin();
            Query qr = session.createQuery("from Employee");
            List allUsers;
            allUsers = qr.list();
            em = new Employee();
            em.setName("new name");
            em.setRole("testing");
            map.put("Person", em);
            map.put("emploee", allUsers);
            map.addAttribute("msg", "Page redirection");
            map.addAttribute("helloAgain", "Hello (Again) Spring from Netbeans!!");
            session.getTransaction().commit();
            return "userlist";
        } else {
            return "index";
        }
    } catch (Exception e) {
        session.beginTransaction().rollback();
        return "PageNotFound";
    } finally {
        if (session.isOpen()) {
            session.close();
        }
    }
}

From source file:edu.ijse.tcd.controller.JobDoneController.java

@RequestMapping(value = "getJobDone", method = RequestMethod.GET)
public String getDetail(ModelMap map, HttpServletRequest request) {
    String jobNumber = request.getParameter("jobnumber");
    ArrayList<JobCard> jobCards = jobCardService.getJobCardDetail(jobNumber);
    JobCard jobCard = new JobCard();
    if (jobCards.size() > 0) {
        jobCard = jobCards.get(0);/*from w w w. j  a  v a2 s  .c  om*/
    }
    ArrayList<JobDone> jobDones = jobDoneService.getJobDones();
    map.addAttribute("jobDoneList", jobDones);

    map.addAttribute("jobCardList", jobCards);
    HttpSession hs = request.getSession();
    hs.getAttribute("jobCardDone");
    hs.setAttribute("jobCardDone", jobCard);
    map.addAttribute("jobCardDone", jobCard);
    return "jobDone";
}