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:mx.com.quadrum.contratos.controller.crud.EmpresaController.java

@ResponseBody
@RequestMapping(value = "agregarEmpresa", method = RequestMethod.POST)
public String agregarEmpresa(@Valid @ModelAttribute("empresa") Empresa empresa, BindingResult bindingResult,
        HttpSession session) {
    if (session.getAttribute("usuario") == null) {
        return SESION_CADUCA;
    }//ww w .j a v  a2 s . c om
    if (bindingResult.hasErrors()) {
        return ERROR_DATOS;
    }
    return empresaService.agregar(empresa);
}

From source file:mx.com.quadrum.contratos.controller.crud.EmpresaController.java

@ResponseBody
@RequestMapping(value = "editarEmpresa", method = RequestMethod.POST)
public String editarEmpresa(@Valid @ModelAttribute("empresa") Empresa empresa, BindingResult bindingResult,
        HttpSession session) {
    if (session.getAttribute("usuario") == null) {
        return SESION_CADUCA;
    }//from  w ww  . j  a v a 2 s . c  om
    if (bindingResult.hasErrors()) {
        return ERROR_DATOS;
    }
    return empresaService.editar(empresa);
}

From source file:de.thm.arsnova.LoginAuthenticationFailureHandler.java

@Override
public void onAuthenticationFailure(final HttpServletRequest request, final HttpServletResponse response,
        final AuthenticationException exception) throws IOException, ServletException {
    HttpSession session = request.getSession();
    if (session != null && session.getAttribute("ars-login-failure-url") != null) {
        failureUrl = (String) session.getAttribute("ars-login-failure-url");
    }//from   w  w w . j  a  v  a  2  s.  c  om

    redirectStrategy.sendRedirect(request, response, failureUrl);
}

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

@RequestMapping(value = "/")
public String home(Model model, HttpSession session) {
    CartBean cart;/*from   w  ww.  j  a va2 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("products", productFacadeLocal.findAll());

    return "home";
}

From source file:com.starr.smartbuilds.controller.RegController.java

@RequestMapping(method = { RequestMethod.GET })
public String getReg(Model model, HttpServletRequest req, HttpServletResponse resp) throws IOException {
    HttpSession session = req.getSession();
    User user = (User) session.getAttribute("user");
    if (user == null) {
        model.addAttribute("authMsg", "<a href='./auth'>Log in</a>");
        model.addAttribute("exitReg", "<a href='./reg'>Register</a>");
    } else {/*w  w w. ja va  2s  .co m*/
        resp.sendRedirect("./");
    }
    model.addAttribute("user", new User());
    return "register";
}

From source file:com.xhm.longxin.qth.web.user.module.screen.AddBuyProduct.java

public void execute(Navigator nav, HttpSession session, Context context) {

    QthUser qthUser = (QthUser) session.getAttribute(UserConstant.QTH_USER_SESSION_KEY);
    if (qthUser == null) {
        nav.redirectTo(UserConstant.LOGIN_RETURN_DEFAULT_LINK);
        return;//www.ja v  a 2  s . c  o  m
    }
    User user = userService.getUserByLoginId(qthUser.getId());
    if (user == null) {
        nav.redirectTo(UserConstant.LOGIN_RETURN_DEFAULT_LINK);
        return;
    }

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

From source file:id.ac.ipb.ilkom.training.controller.LoginController.java

@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(HttpSession session, Model model) {
    String errorMessage = (String) session.getAttribute("errorMessage");
    if (errorMessage != null && errorMessage.trim().length() > 0) {
        model.addAttribute("errorMessage", errorMessage);
        //remove attribute from session
        session.setAttribute("errorMessage", null);
        session.removeAttribute("errorMessage");
    }/*from  ww  w . jav  a 2s .c  om*/
    return "login";
}

From source file:SessionTracker.java

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

    HttpSession session = req.getSession(true);

    Integer count = (Integer) session.getAttribute("count");

    if (count == null) {
        count = new Integer(1);
    } else {//  w ww .j  av  a  2 s  .  com
        count = new Integer(count.intValue() + 1);
    }

    session.setAttribute("count", count);
    out.println("<html><head><title>SessionSnoop</title></head>");
    out.println("<body><h1>Session Details</h1>");
    out.println(
            "You've visited this page " + count + ((count.intValue() == 1) ? " time." : " times.") + "<br/>");
    out.println("<h3>Details of this session:</h3>");
    out.println("Session id: " + session.getId() + "<br/>");
    out.println("New session: " + session.isNew() + "<br/>");
    out.println("Timeout: " + session.getMaxInactiveInterval() + "<br/>");
    out.println("Creation time: " + new Date(session.getCreationTime()) + "<br/>");
    out.println("Last access time: " + new Date(session.getLastAccessedTime()) + "<br/>");
    out.println("</body></html>");
}

From source file:echec.controller.PartieController.java

@RequestMapping(value = "/partie_en_cours", method = RequestMethod.GET)
public String partieEnCours(Model model, HttpSession s) {
    Long joueur = (long) s.getAttribute("idUser");
    model.addAttribute("listePartie", servicePartie.findAllByBlancId(joueur));
    return "_PARTIE_EN_COURS.jsp";
}

From source file:com.swiftcorp.portal.common.web.ForwardUtil.java

public ActionForward promtHomePage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws SystemException, BusinessRuleViolationException {
    log.info("promtHomePage() : enter");
    HttpSession session = request.getSession();

    UserDTO userDTO = (UserDTO) session.getAttribute(SESSION_KEYS.USER);
    return mapping.findForward(ForwardNames.USER_HOME);

}