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:be.fedict.eid.dss.sp.servlet.DownloadServlet.java

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

    LOG.debug("doGet");
    HttpSession httpSession = request.getSession();
    byte[] document = (byte[]) httpSession.getAttribute("document");

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http 1.1
    if (!request.getScheme().equals("https")) {
        // else the download fails in IE
        response.setHeader("Pragma", "no-cache"); // http 1.0
    } else {//ww  w  . jav  a2 s.co  m
        response.setHeader("Pragma", "public");
    }
    response.setDateHeader("Expires", -1);
    response.setContentLength(document.length);

    String contentType = (String) httpSession.getAttribute("ContentType");
    LOG.debug("content-type: " + contentType);
    response.setContentType(contentType);
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}

From source file:com.att.api.immn.controller.CreateIndexController.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final HttpSession session = request.getSession();
    OAuthToken token = (OAuthToken) session.getAttribute("token");
    IMMNService srvc = new IMMNService(appConfig.getApiFQDN(), token);

    JSONObject jresponse = new JSONObject();
    try {/*from  w w  w.  ja  v  a  2 s  .  c o m*/
        srvc.createMessageIndex();
        jresponse.put("success", true).put("text", "Message index created.");
    } catch (RESTException re) {
        jresponse.put("success", false).put("text", re.getMessage());
    }

    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    writer.print(jresponse);
    writer.flush();
}

From source file:com.elastacloud.aad.adal4jpassive.PassiveController.java

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public String getPassiveAuth(ModelMap model, HttpServletRequest httpRequest) {
    try {// w ww  .j a  va2  s. com
        HttpSession session = httpRequest.getSession();
        String token = (String) session.getAttribute("token");
        boolean verified = (boolean) session.getAttribute("verified");
        if (verified == false) {
            model.addAttribute("error", new Exception("AuthenticationResult not found in session."));
            return "/error";
        } else {

            try {
                SignedJWT jwt = SignedJWT.parse(token);
                String upn = (String) jwt.getPayload().toJSONObject().get("upn");
                model.addAttribute("username", upn);

            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        return "/secure/passive";
    } catch (Exception e) {
        model.addAttribute("error", new Exception("AuthenticationResult not found in session."));
        return "/error";
    }
}

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

@RequestMapping(value = "/cart/remove", method = RequestMethod.POST)
public String removeProduct(@RequestParam(value = "idProduct") Integer idProduct, HttpSession session) {
    CartBean cart;//from   www. j  av a2  s .  c  o  m
    if (session.getAttribute("cart") == null) {
        cart = new CartBean();
    } else {
        cart = (CartBean) session.getAttribute("cart");
    }
    ecomBeanFrontLocal.removeProductFromCart(cart, idProduct, 1);
    session.setAttribute("cart", cart);
    return "redirect:/cart";
}

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

@ResponseBody
@RequestMapping(value = "agregarContacto", method = RequestMethod.POST)
public String agregarContacto(@Valid @ModelAttribute("contacto") Contacto contacto, BindingResult bindingResult,
        HttpSession session) {
    if (session.getAttribute("usuario") == null) {
        return SESION_CADUCA;
    }// ww w. j ava 2 s.com
    if (bindingResult.hasErrors()) {
        for (ObjectError e : bindingResult.getAllErrors()) {
            System.out.println(e.getCode());
            System.out.println(e.getDefaultMessage());
            System.out.println(e.getObjectName());
            System.out.println(e.toString());
        }
        return ERROR_DATOS;
    }
    if (contactoService.existeCorreo(contacto.getMail())) {
        return "Error...#Ya existe un usuario con el correo que quiere ingresar.";
    }
    return contactoService.agregar(contacto);
}

From source file:controller.ImageCTMH.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    HttpSession session = request.getSession();
    String mamh = session.getAttribute("mamh").toString();
    session.removeAttribute("mamh");
    if (!ServletFileUpload.isMultipartContent(request)) {
        out.println("Nothing to upload");
        return;/*from  www .  j a v a  2s.  c  o m*/
    }
    FileItemFactory itemfactory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(itemfactory);
    String a = "";
    try {
        List<FileItem> items = upload.parseRequest(request);
        for (FileItem item : items) {
            String myfolder = ("asset/Images") + "/";
            File uploadDir = new File(
                    "E:/Cng ngh phn m?m/? ?n/1996Shop/ShopOnline/web/asset/Images");
            File file = File.createTempFile("img", ".png", uploadDir);
            item.write(file);
            a = myfolder + file.getName();
            ct.setHinhAnh(a);
            ct.setMaMh(Long.parseLong(mamh));
            cTHinhAnhDAO.insert(ct);
            response.sendRedirect("CTSanPham.jsp?MaMH=" + mamh + "");
        }

    } catch (FileUploadException e) {
        out.println("upload fail");
    } catch (Exception ex) {

    }
}

From source file:com.bitranger.parknshop.buyer.controller.CustomerLogin.java

@RequestMapping("/login")
public String customerLogin(HttpServletRequest req, String email, String password, String role) {

    HttpSession session = req.getSession(true);
    if (session.getAttribute("currentCustomer") != null || session.getAttribute("currentSeller") != null)
        return "redirect:/";
    if (role == null || email == null)
        return Utility.error("Role unspecified.");
    if (role.equals("buyer")) {
        PsCustomer persistCustomer = psCustomerDao.findByEmail(email);
        System.out.println("CustomerLogin.customerLogin()");
        System.out.println(persistCustomer);
        if (persistCustomer != null) {
            System.out.println(persistCustomer.getEmail());
            System.out.println(persistCustomer.getPassword());
        }// w w w  . j  av a 2 s . co  m
        if (persistCustomer == null)
            //|| !persistCustomer.getPassword().equals(password))
            return "redirect:/";

        session.setAttribute("currentCustomer", persistCustomer);

        System.out.println("CustomerLogin.customerLogin()");
        System.out.println("================================================");
        System.out.println(req.getSession().getAttribute("currentCustomer"));

        if (persistCustomer == null || !persistCustomer.getPassword().equals(password))
            return "redirect:/";
        session.setAttribute("currentCustomer", persistCustomer);
        return "redirect:/";
    }
    if (role.equals("seller")) {
        PsSeller persistSeller = psSellerDao.findByEmail(email);
        if (persistSeller == null || !persistSeller.getPassword().equals(password))
            return Utility.error("Password Error.");
        session.setAttribute("currentSeller", persistSeller);
        return "redirect:/";
    }
    return Utility.error("Params Role Error");
}

From source file:io.github.benas.todolist.web.servlet.todo.CreateTodoServlet.java

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

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

    String title = request.getParameter("title");
    String dueDate = request.getParameter("dueDate");
    String priority = request.getParameter("priority");

    Todo todo = new Todo(user.getId(), title, false, Priority.valueOf(priority), new Date(dueDate));
    todoService.create(todo);/*from   w  w  w .  j  a  va2s.  c  o  m*/
    request.getRequestDispatcher("/todos").forward(request, response);

}

From source file:com.safasoft.treeweb.auth.CustomAuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication auth) throws IOException, ServletException {
    //login info/* w  w  w .  ja  va 2 s  . c o  m*/
    HttpSession session = request.getSession();
    String cnname = (String) session.getAttribute("cnname");
    if (cnname == null || cnname.equals("")) {
        try {
            String principal = auth.getPrincipal().toString();
            int start = principal.indexOf("cn=");
            String tmp = principal.substring(start + 3);
            int end = tmp.indexOf(",");
            cnname = tmp.substring(0, end);
            session.setAttribute("cnname", cnname);
            session.setAttribute("uid", auth.getName());
            session.setAttribute("sessionid", session.getId());
        } catch (Exception ex) {
            authLogger.error(ex);
        }
    }
    //logging login
    FfLogFocus logFocus = new FfLogFocus();
    logFocus.setUserName(auth.getName());
    DataConverter dc = new DataConverter();
    dc.setConverter(new Date(), "dd-MMM-yyyy kk:mm:ss");
    logFocus.setLoginTime(dc.getConverter());
    FfLogFocus logFocusSave = new SessionUtil<FfLogFocusService>().getAppContext("ffLogFocusService")
            .save(logFocus);
    session.setAttribute("logParentId", logFocusSave.getId());
    //redirect
    setDefaultTargetUrl("/apps/main/home");
    super.onAuthenticationSuccess(request, response, auth);
}

From source file:edu.pitt.sis.infsci2730.finalProject.web.UserController.java

@RequestMapping(value = "", method = RequestMethod.GET)
public ModelAndView mypage(HttpSession session) {
    CustomerDBModel customer = (CustomerDBModel) session.getAttribute("customer");
    if (customer == null) {
        return new ModelAndView("index");
    } else {//from ww w.ja  va  2 s .c o m
        return new ModelAndView("customerProfile", "customer", customer);
    }
}