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:CounterServer.java

public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpSession session = req.getSession(true);
    int count = 1;
    Integer i = (Integer) session.getAttribute(COUNTER_KEY);
    if (i != null) {
        count = i.intValue() + 5;//from   w w  w.j a  va2  s.co  m
    }
    session.setAttribute(COUNTER_KEY, new Integer(count));
    DataInputStream in = new DataInputStream(req.getInputStream());
    resp.setContentType("application/octet-stream");
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(byteOut);
    out.writeInt(count);
    out.flush();
    byte[] buf = byteOut.toByteArray();
    resp.setContentLength(buf.length);
    ServletOutputStream servletOut = resp.getOutputStream();
    servletOut.write(buf);
    servletOut.close();
}

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

@RequestMapping(method = { RequestMethod.GET })
public String getAuth(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 {//from  ww  w  .  j a va 2s  . c o m
        resp.sendRedirect("./");
    }
    model.addAttribute("auth", new AuthService());
    return "authorization";
}

From source file:vmware.au.se.sqlfireweb.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() + "/sqlfireweb/login");
        return null;
    }//from  w ww . j av  a  2 s.  co m

    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:br.edu.ifrn.pdscfyp.Controller.MainController.java

@RequestMapping("/index")
public String index(HttpSession session, Model model) {

    Usuario u = (Usuario) session.getAttribute("usuarioLogado");

    model.addAttribute("usuarioLogado", u);
    model.addAttribute("sessao", session);

    if (session.getAttribute("jaPassou") != null && (boolean) session.getAttribute("jaPassou") == true) {
        String a = (String) session.getAttribute("falhaLogin");
        model.addAttribute("dadosInvalidos", a);
        session.setAttribute("jaPassou", false);
    } else {/*from w ww .jav a  2 s.  co  m*/
        session.setAttribute("jaPassou", false);
    }

    return "index";
}

From source file:com.googlecode.psiprobe.controllers.jsp.DisplayJspController.java

protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    boolean compile = ServletRequestUtils.getBooleanParameter(request, "compile", false);

    HttpSession session = request.getSession(true);
    Summary summary = (Summary) session.getAttribute(SUMMARY_ATTRIBUTE);
    if (summary == null || !contextName.equals(summary.getName())) {
        summary = new Summary();
        summary.setName(contextName);//from  w w w . j a v a 2s  . c om
    }
    getContainerWrapper().getTomcatContainer().listContextJsps(context, summary, compile);

    session.setAttribute(SUMMARY_ATTRIBUTE, summary);

    if (compile) {
        return new ModelAndView(new RedirectView(
                request.getRequestURI() + "?webapp=" + (contextName.length() == 0 ? "/" : contextName)));
    } else {
        return new ModelAndView(getViewName(), "summary", summary);
    }
}

From source file:com.zte.gu.webtools.web.download.DownloadController.java

@RequestMapping(method = RequestMethod.GET)
public void download(HttpSession session, HttpServletResponse response) {
    String filePath = (String) session.getAttribute("filePath");
    String fileName = (String) session.getAttribute("fileName");
    if (filePath != null) {
        response.reset();//from  w w  w. ja va  2s  . c o  m
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        response.setContentType("application/octet-stream; charset=UTF-8");
        InputStream in = null;
        try {
            in = new FileInputStream(filePath);
            IOUtils.copy(in, response.getOutputStream());
        } catch (Exception e) {
            LoggerFactory.getLogger(DownloadController.class).warn("download error,", e);
        } finally {
            IOUtils.closeQuietly(in);
            session.removeAttribute("filePath");
            session.removeAttribute("fileName");
        }
    }
}

From source file:de.berlios.jhelpdesk.web.preferences.filter.CustomFilterController.java

@RequestMapping(value = "/preferences/filters/list.html", method = RequestMethod.GET)
public String showAllFilters(ModelMap map, HttpSession session) {

    User currentUser = (User) session.getAttribute("user");
    map.addAttribute("filters", ticketFilterDAO.getAllFiltersForUser(currentUser));

    return "preferences/filters/showAll";
}

From source file:net.bafeimao.umbrella.web.controller.CaptchaController.java

@RequestMapping(value = "/match", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody//from   w w w  . j  av a 2s  .com
public String match(HttpSession session, String text) {
    String captchaText = session.getAttribute(Constants.KAPTCHA_SESSION_KEY).toString();
    if (text != null && text.equals(captchaText)) {
        return "{\"result\":true}";
    } else {
        return "{\"result\":false}";
    }
}

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

@RequestMapping("/register")
public String viewRegistration(Map<String, Object> model, HttpSession logsession) {

    String username = (String) logsession.getAttribute("username");
    if (!username.equals("") && username.trim().length() != 0) {
        User userForm = new User();
        model.put("userForm", userForm);

        List<String> professionList = new ArrayList<>();
        professionList.add("Developer");
        professionList.add("Designer");
        professionList.add("IT Manager");
        model.put("professionList", professionList);
        return "register";
    } else {/*from   ww  w  . ja v a 2s .co  m*/
        return "index";
    }
}

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

@Override
public void onApplicationEvent(HttpSessionDestroyedEvent e) {
    //set logout time
    HttpSession session = e.getSession();
    if (session != null) {
        Object obj = session.getAttribute("logParentId");
        if (obj != null) {
            int logParentId = (Integer) obj;
            FfLogFocusService flfService = new SessionUtil<FfLogFocusService>()
                    .getAppContext("ffLogFocusService");
            FfLogFocus logFocus = flfService.getById(logParentId);
            DataConverter dc = new DataConverter();
            dc.setConverter(new Date(), "dd-MMM-yyyy kk:mm:ss");
            logFocus.setLogoutTime(dc.getConverter());
            flfService.save(logFocus);/*from   ww w .  j  ava  2s.c  om*/
        }
    }
}