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:id.ac.ipb.ilkom.training.controller.OrderController.java

@RequestMapping(value = "/cart", method = RequestMethod.GET)
public String cart(Model model, HttpSession session) {
    Customer customer = (Customer) session.getAttribute("customer");
    if (customer == null) {
        return "redirect:/";
    }/*from   w w  w . j a  v a2  s  . c  o  m*/
    return "cart";
}

From source file:be.fedict.eid.applet.service.PdfServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug("doGet");

    HttpSession httpSession = request.getSession();
    EIdData eIdData = (EIdData) httpSession.getAttribute("eid");

    byte[] document;
    try {/*from  w  w w  . ja  v a  2 s  .c om*/
        document = this.pdfGenerator.generatePdf(eIdData);
    } catch (DocumentException e) {
        throw new ServletException("PDF generator error: " + e.getMessage(), e);
    }

    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");

    response.setContentType("application/pdf");
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}

From source file:be.fedict.eid.applet.service.VcardServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug("doGet");

    HttpSession httpSession = request.getSession();
    EIdData eIdData = (EIdData) httpSession.getAttribute("eid");

    byte[] document;
    try {/*from w  ww .j a va2s .  co m*/
        document = this.vcardGenerator.generateVcard(eIdData);
    } catch (IOException e) {
        throw new ServletException("vCard generator error: " + e.getMessage(), e);
    }

    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");

    response.setContentType(VcardLight.MIME_TYPE);
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}

From source file:org.openmrs.module.conceptsearch.web.controller.AbstractSearchFormController.java

public void switchToPage(@RequestParam("page") String page, ModelMap model, WebRequest request,
        HttpSession session) {

    PagedListHolder resListHolder = (PagedListHolder) session.getAttribute("sortResults");
    if (resListHolder != null) {
        if ("previous".equals(page)) {
            resListHolder.previousPage();
        } else if ("next".equals(page)) {
            resListHolder.nextPage();//from   w  ww  . ja v a  2 s  .c  o m
        } else {
            resListHolder.setPage(Integer.parseInt(page));
        }
        model.addAttribute("searchResult", resListHolder);
    } else {
        log.warn("Results are gone");
    }
}

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

@RequestMapping(value = "/preferences", method = RequestMethod.GET)
public String showPreferences(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 {/*from  ww w . j  a v  a  2  s. c o  m*/
        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 preferences");

    model.addAttribute("userPref", (UserPref) session.getAttribute("prefs"));

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

From source file:com.neu.controller.AdditionSuccessController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    //throw new UnsupportedOperationException("Not yet implemented");
    int result = 0;
    DataSource ds = (DataSource) this.getApplicationContext().getBean("myDataSource");
    ModelAndView mv = new ModelAndView();
    HttpSession session = request.getSession();
    int count = (Integer) (session.getAttribute("count"));

    try {//  w  w  w.j  av  a2  s  .  c o  m

        QueryRunner run = new QueryRunner(ds);
        ResultSetHandler<Books> books = new BeanHandler<Books>(Books.class);

        for (int i = 1; i <= count; i++) {

            String isbnField = "isbn" + i;
            String titleField = "title" + i;
            String authorField = "author" + i;
            String priceField = "price" + i;

            String isbn = request.getParameter(isbnField).replaceAll("<|>|@|;|,|=|}|$|&", "");
            String title = request.getParameter(titleField).replaceAll("<|>|@|;|,|=|}|$|&", "");
            String author = request.getParameter(authorField).replaceAll("<|>|@|;|,|=|}|$|&", "");
            float price = Float
                    .parseFloat(request.getParameter(priceField).replaceAll("<|>|@|;|,|=|}|$|&", ""));

            Object[] params = new Object[4];
            params[0] = isbn;
            params[1] = title;
            params[2] = author;
            params[3] = price;

            result = run.update("Insert into books(isbn,title,authors,price) values(?,?,?,?)", params);

        }
    } catch (Exception ex) {
        System.out.println("Details Not Added In DB!! " + ex.getMessage());
    }
    if (result > 0) {
        mv.setViewName("success");
    } else {
        mv.setViewName("error");
    }
    return mv;
}

From source file:cs544.wamp_blog_engine.controller.BlogController.java

@RequestMapping(value = "/blog", method = RequestMethod.GET)
public String getAllBlog(Model model, HttpSession session) {
    User u = (User) session.getAttribute("loggedUser");
    if (u != null && u.getUserCredential().isBLogger()) {
        u = userService.getUser(u.getId());
        model.addAttribute("blogList", u.getUserBlogs());//
    } else {//from ww  w.  jav  a2s .c o  m
        model.addAttribute("blogList", blogerService.getAllBlogs());
    }
    return "blogList";
}

From source file:io.github.benas.todolist.web.servlet.user.account.UpdateAccountServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String name = request.getParameter("name");
    String email = request.getParameter("email");

    HttpSession session = request.getSession();
    User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

    if (isAlreadyUsed(email) && isDifferent(email, user.getEmail())) {
        request.setAttribute("error",
                MessageFormat.format(resourceBundle.getString("account.email.alreadyUsed"), email));
        request.setAttribute("user", user);
        request.getRequestDispatcher(ACCOUNT_PAGE).forward(request, response);
        return;/*  w w w .ja  v  a 2  s.  c  o  m*/
    }

    user.setName(name);
    user.setEmail(email);
    userService.update(user);
    request.setAttribute("updateProfileSuccessMessage",
            resourceBundle.getString("account.profile.update.success"));
    request.getRequestDispatcher("/user/account").forward(request, response);

}

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

@RequestMapping(value = "/login", method = RequestMethod.GET)
public String formSetup(Model model, HttpSession session) {
    CartBean cart;//w w  w.  j  a v  a 2  s  .c om
    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());
    return "login";
}

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

@RequestMapping(value = "/signup", method = RequestMethod.GET)
public String signupForm(Model model, HttpSession session) {
    CartBean cart;/*from w w  w  .  j a  v  a  2s  . 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());
    return "signup";
}