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.leapfrog.springhibernate.filter.AuthInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
    HttpSession session = request.getSession();
    Boolean checking = (Boolean) session.getAttribute("LoggedIn");
    if (checking == null || checking == false) {
        response.sendRedirect(request.getContextPath());
        return false;
    } else {//ww  w.ja  v  a 2 s.co  m
        return true;
    }

}

From source file:com.mobilewallet.admin.action.AdminAction.java

/**
 * This is the action called from the Struts framework.
 *
 * @param mapping The ActionMapping used to select this instance.
 * @param form The optional ActionForm bean for this request.
 * @param request The HTTP Request we are processing.
 * @param response The HTTP Response we are processing.
 * @throws java.lang.Exception// ww w .j a  v a2  s  .  c  om
 * @return
 */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    HttpSession session = request.getSession(false);
    if (session == null || session.getAttribute("adminUser") == null) {
        return mapping.findForward(SHOW_ADMIN_HOME);
    }
    return mapping.findForward(DISPLAY_LOGINPAGE);
}

From source file:com.alibaba.sample.petstore.web.store.module.screen.ViewCart.java

public void execute(HttpSession session, Context context) throws Exception {
    Cart cart = (Cart) session.getAttribute(PETSTORE_CART_KEY);

    if (cart == null) {
        cart = new Cart();
    }/*  w ww.ja v a 2  s.  co m*/

    cart = storeManager.getCartItems(cart);

    context.put("cart", cart);
}

From source file:com.zuoxiaolong.blog.common.authorization.AuthorizationInterceptor.java

private void checkLogin(HttpServletRequest request) {
    HttpSession session = request.getSession();
    if (ObjectUtils.isEmpty(session.getAttribute("username"))) {
        throw new BusinessException(ExceptionType.AUTHORIZATION_ERROR);
    }//  ww  w .  j  a  v a 2 s .c  o m
}

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("tracker.count");
    if (count == null)
        count = new Integer(1);
    else/*from   w w w  .  j ava2 s  . c  o m*/
        count = new Integer(count.intValue() + 1);
    session.setAttribute("tracker.count", count);

    out.println("<HTML><HEAD><TITLE>SessionTracker</TITLE></HEAD>");
    out.println("<BODY><H1>Session Tracking Demo</H1>");

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

    out.println("<P>");

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

From source file:com.horas.web.CommentController.java

/**
 *
 * @param comment/*from   w w  w.j  a  v a 2  s. co  m*/
 * @return
 */
@RequestMapping(value = "/addcomments", method = RequestMethod.POST)
@ResponseBody
public ResponseMessage addCommentNews(@RequestBody Comment comment, HttpServletRequest request) {
    String username;
    HttpSession sess = request.getSession();
    username = (String) sess.getAttribute("username");
    comment.setIdComment(sys_guid());
    //  comment.setIdNews(sys_guid());
    comment.setUserComment(username);
    comment.setIpComment("127.0.0.2");
    comment.setDateComment(new Date());
    commentService.addCommentNews(comment);
    return new ResponseMessage(ResponseMessage.Type.success, "commentAdded");
}

From source file:com.lixiaocong.service.ImageCodeService.java

public boolean check(String code, HttpSession session) {
    Object imagecode = session.getAttribute("imagecode");
    return imagecode != null && code.toLowerCase().equals(((String) imagecode).toLowerCase());
}

From source file:gxu.software_engineering.shen10.market.interceptor.AdminInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    HttpSession session = request.getSession(false);
    if (session == null || session.getAttribute(ADMIN) == null) {
        throw new RuntimeException("?????");
    }/*from  w ww  .  j  a va  2s  . c o  m*/
    return true;
}

From source file:gxu.software_engineering.shen10.market.interceptor.UserInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    HttpSession session = request.getSession(false);
    if (session == null || session.getAttribute(Consts.USER) == null) {
        throw new RuntimeException("?????");
    }// www . j  a v a 2s.com
    return true;
}

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

@RequestMapping(value = "/stores", method = RequestMethod.GET)
public String stores(Model model, HttpSession session) {
    CartBean cart;/*  w w w.j  a v  a 2 s. c  o  m*/
    if (session.getAttribute("cart") == null) {
        cart = new CartBean();
    } else {
        cart = (CartBean) session.getAttribute("cart");
        session.setAttribute("cart", cart);
    }

    model.addAttribute("cartTotalValue", ecomBeanFrontLocal.getTotalValue(cart));
    model.addAttribute("nbProducts", ecomBeanFrontLocal.getCartContents(cart).size());
    List<Category> categories = categoryFacade.findAll();
    model.addAttribute("categories", categories);

    model.addAttribute("stores", storeFacadeLocal.findAll());

    return "stores";
}