List of usage examples for javax.servlet.http HttpSession getAttribute
public Object getAttribute(String name);
null
if no object is bound under the name. From source file:com.job.portal.servlets.CompanyServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); JSONArray arr = null;/*w ww .j av a2s. co m*/ String param = null; Map<String, String[]> m = request.getParameterMap(); CompanyManager cm = new CompanyManager(); HttpSession sess = request.getSession(false); UserDetails ud = (UserDetails) sess.getAttribute("user"); CompanyMaster cMaster = null; try { obj.put("status", false); if (request.getParameter("param") != null) { param = request.getParameter("param"); if (param.equalsIgnoreCase("addCompany")) { cMaster = cm.addCompany(m, ud); if (cMaster != null && cMaster.getCompanyId() > 0) { obj.put("status", true); obj.put("msg", "Company added"); } else { obj.put("msg", "There seems to be some problem try again later"); } } } } catch (Exception e) { LogOut.log.error("In " + new Object() { }.getClass().getEnclosingClass().getName() + "." + new Object() { }.getClass().getEnclosingMethod().getName() + " " + e); } finally { out.close(); } }
From source file:bc8.movies.controllers.LoginController.java
@RequestMapping(value = "/userDetails") public ModelAndView userDetails(String user, HttpSession session) { ModelAndView mv = new ModelAndView("userDetails"); if (session.getAttribute("user") == null) { mv.setViewName("redirect:/home"); }// w ww .j a v a 2 s. co m return mv; }
From source file:com.kalai.controller.HibernateValidatorController.java
@RequestMapping("/springvalidation") public String hibernate_valdiate(HttpSession session, ModelMap map) { String username = ""; try {/*w ww . j a v a2s .com*/ username = (String) session.getAttribute("username"); if (!username.equals("") && username.trim().length() != 0) { map.addAttribute("status", "entry"); return "hibernatevalidate"; } else { return "index"; } } catch (Exception e) { return "PageNotFound"; } }
From source file:edu.txstate.dmlab.clusteringwiki.web.IndexController.java
@RequestMapping("index.*") public String getIndexPage(HttpServletRequest request, HttpServletResponse response, Model model) { if (request.getParameter("test") != null) { String executionId = request.getParameter("test").toLowerCase(); if (executionId.equals("train")) { //user is requesting the training track. Generate a new unique ID for this test executionId = testExecutionDao.addTrainingTest(); return "redirect:index.html?test=" + executionId; }/*from ww w.ja va 2 s . co m*/ if (isValidExecutionId(executionId)) { //starting test final HttpSession session = request.getSession(true); if (session.getAttribute("testId") != null && !session.getAttribute("testId").equals(executionId)) { request.setAttribute("message", "A test is already in progress in this session.<br>" + "Please finish the current test of stop the test from the top menu before starting another."); return "pageError"; } session.setAttribute("executionId", executionId); } else { request.setAttribute("message", "Your test execution id is invalid. Please try again."); return "pageError"; } } else if (request.getParameter("endTest") != null) { //end in progress test final HttpSession session = request.getSession(false); if (session != null) session.removeAttribute("executionId"); } return "index"; }
From source file:mx.com.quadrum.contratos.controller.crud.ContratoController.java
@RequestMapping(value = "contratoUsuario", method = RequestMethod.GET) public String contrato(Model model, HttpSession session) { Usuario usuario = (Usuario) session.getAttribute("usuario"); List<Permiso> permisos = (List<Permiso>) session.getAttribute(PERMISOS); if (usuario == null || permisos == null) { return "templates/index"; }//from w ww . j av a 2 s. c om if (usuario.getEsAdmin()) { model.addAttribute("esAdmin", "esAdmin"); } if (usuarioService.tienePermiso(usuario, "contratoUsuario")) { return "templates/noAutorizado"; } model.addAttribute("permisos", permisos); model.addAttribute("tipoContrato", tipoContratoService.buscarTodos()); model.addAttribute("estado", estatusService.buscarTodos()); model.addAttribute("contratos", contratoService.buscarTodos()); model.addAttribute("usuarios", usuarioService.buscarTodos()); return "crud/contrato"; }
From source file:com.job.portal.manager.JobApplicationsManager.java
public JSONObject apply(HttpServletRequest request) { JSONObject obj = new JSONObject(), obj1 = null; boolean flag = false; JobApplicationsDAO jad = new JobApplicationsDAO(); try {/* www. j a va 2s . co m*/ obj.put("status", flag); HttpSession sess = request.getSession(false); obj1 = (JSONObject) sess.getAttribute("user"); String jobId = request.getParameter("jobId"); if (jobId != null && ExpressionCheck.checkNumber(jobId)) { if (obj1.has("userId")) { flag = jad.applyForJob(jobId, obj1.getString("userId")); obj.put("status", flag); if (flag) { obj.put("msg", "Successfully Applied"); } else { obj.put("msg", "There seems to be some problem please try again after sometime"); } } else { obj.put("msg", "Please log in to continue"); } } else { obj.put("msg", "Invalid job id"); } } catch (Exception e) { LogOut.log.error("In " + new Object() { }.getClass().getEnclosingClass().getName() + "." + new Object() { }.getClass().getEnclosingMethod().getName() + " " + e); } finally { return obj; } }
From source file:SessionSnoop.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("count"); if (count == null) count = new Integer(1); else//from w w w .ja v a 2 s . co m count = new Integer(count.intValue() + 1); session.setAttribute("count", count); out.println("<HTML><HEAD><TITLE>Session Count</TITLE></HEAD>"); out.println("<BODY><H1>Session Count</H1>"); out.println("You've visited this page " + count + ((count == 1) ? " time." : " times.")); out.println("<P>"); out.println("<H3>Here is your saved session data:</H3>"); Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println(name + ": " + session.getAttribute(name) + "<BR>"); } out.println("<H3>Here are some vital stats on your session:</H3>"); out.println("Session id: " + session.getId() + " <I>(keep it secret)</I><BR>"); out.println("New session: " + session.isNew() + "<BR>"); out.println("Timeout: " + session.getMaxInactiveInterval()); out.println("<I>(" + session.getMaxInactiveInterval() / 60 + " minutes)</I><BR>"); out.println("Creation time: " + session.getCreationTime()); out.println("<I>(" + new Date(session.getCreationTime()) + ")</I><BR>"); out.println("Last access time: " + session.getLastAccessedTime()); out.println("<I>(" + new Date(session.getLastAccessedTime()) + ")</I><BR>"); out.println("Requested session ID from cookie: " + req.isRequestedSessionIdFromCookie() + "<BR>"); out.println("Requested session ID from URL: " + req.isRequestedSessionIdFromURL() + "<BR>"); out.println("Requested session ID valid: " + req.isRequestedSessionIdValid() + "<BR>"); out.println("<H3>Test URL Rewriting</H3>"); out.println("Click <A HREF=\"" + res.encodeURL(req.getRequestURI()) + "\">here</A>"); out.println("to test that session tracking works via URL"); out.println("rewriting even when cookies aren't supported."); out.println("</BODY></HTML>"); }
From source file:FormLogin.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException { resp.setContentType("text/html"); java.io.PrintWriter out = resp.getWriter(); resp.setHeader("Expires", "Tues, 01 Jan 1980 00:00:00 GMT"); String uri = req.getRequestURI(); HttpSession session = req.getSession(); String user = (String) session.getAttribute(USER_KEY); if (user == null) { login(out, uri);/*from ww w . j a v a 2s . c om*/ return; } out.println("<html>"); out.println("<head>"); out.println("<title>Welcome</title>"); out.println("</head>"); out.println("<body>"); out.println("<center><h2>Welcome to our site!</h2>"); out.println("</center><br><br>"); out.println("</body>"); out.println("</html>"); out.flush(); }
From source file:com.eftech.wood.controllers.ControllerCartPhone.java
@RequestMapping(value = "/del-from-basket", method = RequestMethod.GET) public String del_from_basket1(@RequestParam("id") int id, HttpSession session) { ShoppingCart shoppingCart = (ShoppingCart) session.getAttribute("cart"); if (shoppingCart == null) shoppingCart = new ShoppingCart(); // Iphone iphone = iphoneJDBCTemplate.getIphone(id); // shoppingCart.update(iphone, "0"); // delete from compare session.setAttribute("cart", shoppingCart); String page = "index"; try {//from w w w.j a v a2s.co m page = (String) session.getAttribute("page"); } catch (Exception e) { } return "redirect:/" + page + ".htm"; }
From source file:de.berlios.jhelpdesk.web.ticket.UploadFileController.java
private synchronized void addPathToSession(HttpSession session, String path) { Queue<String> paths = (Queue<String>) session.getAttribute("paths"); if (!paths.contains(path)) { paths.add(path);/*from w w w . j ava 2 s. co m*/ } }