List of usage examples for javax.servlet.http HttpSession setAttribute
public void setAttribute(String name, Object value);
From source file:cs425.yogastudio.controller.CustomerController.java
@RequestMapping(value = "/customer/{id}", method = RequestMethod.GET) public String update(Model model, @PathVariable int id, HttpSession session) { session.setAttribute("customer", customerService.get(id)); model.addAttribute("customer", customerService.get(id)); // return "customerUpdate"; }
From source file:com.jaspersoft.jasperserver.war.util.SessionDecoratorFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String sessionDecorator = request.getParameter(SESSION_DECORATOR); if (!StringUtils.isEmpty(sessionDecorator)) { if (request instanceof HttpServletRequest) { HttpSession session = ((HttpServletRequest) request).getSession(); session.setAttribute(SESSION_DECORATOR, sessionDecorator); }//from ww w . j a v a 2 s . com } chain.doFilter(request, response); }
From source file:com.dangdang.ddframe.job.console.controller.RegistryCenterController.java
private boolean setRegistryCenterNameToSession(final RegistryCenterConfiguration regCenterConfig, final HttpSession session) { session.setAttribute(REG_CENTER_CONFIG_KEY, regCenterConfig); try {//from w w w. j a v a 2 s. co m RegistryCenterFactory.createCoordinatorRegistryCenter(regCenterConfig.getZkAddressList(), regCenterConfig.getNamespace(), Optional.fromNullable(regCenterConfig.getDigest())); } catch (final RegException ex) { return false; } return true; }
From source file:de.iew.web.utils.WebAutoLogin.java
public void autoLogin(UserDetails userDetails, HttpServletRequest request) { SecurityContext securityContext = SecurityContextHolder.getContext(); HttpSession session = request.getSession(true); session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, securityContext); try {//from w w w .j a v a2s. c om // @TODO Das funktioniert so nicht direkt. Habe es ohne Passwort Angabe nicht hinbekommen. UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( userDetails.getUsername(), "test", userDetails.getAuthorities()); token.setDetails(new WebAuthenticationDetails(request)); Authentication authentication = this.authenticationManager.authenticate(token); securityContext.setAuthentication(authentication); } catch (Exception e) { if (log.isInfoEnabled()) { log.info("Fehler whrend des Einlog-Versuchs.", e); } securityContext.setAuthentication(null); } }
From source file:com.liusoft.dlog4j.servlet.DLOG_RandomImageServlet.java
/** * ????HTTP?/*w ww .j av a2 s . co m*/ */ protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { boolean gif_enabled = RequestUtils.support(req, "image/gif") || !RequestUtils.support(req, "image/png"); HttpSession ssn = req.getSession(true); String randomString = random(); ssn.setAttribute(Globals.RANDOM_LOGIN_KEY, randomString); res.setContentType(gif_enabled ? "image/gif" : "image/png"); res.setHeader("Pragma", "No-cache"); res.setHeader("Cache-Control", "no-cache"); res.setDateHeader("Expires", 0); render(randomString, gif_enabled, res.getOutputStream()); }
From source file:com.test.servlet.LoginController.java
@Override public void setResponse(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter writer = response.getWriter(); String email = getParam(RequestParam.email.toString()); String password = getParam(RequestParam.password.toString()); if (Utility.isStringEmpty(email)) { writer.print(//from w w w. ja va 2 s.co m Utility.generalErrorMessage(ResponseCode.email_not_provided.toString(), "Email is required!")); return; } if (Utility.isStringEmpty(password)) { writer.print(Utility.generalErrorMessage(ResponseCode.password_not_provided.toString(), "Password is required!")); return; } DBUtility dbUtil = new DBUtility(servlet); User user = dbUtil.getUser(email, password); if (user != null) { HttpSession session = request.getSession(); session.setAttribute("user_id", user.getId()); String sessionKey = SessionGenerator.getInstance().nextSessionId(); Cookie cookie = new Cookie("auth_key", sessionKey); cookie.setMaxAge(Constants.COOKIE_AGE); response.addCookie(cookie); dbUtil.insertSession(sessionKey, user.getId()); JSONObject jResponse = new JSONObject(); jResponse.put(JSONKey.status.toString(), 0); //jResponse.put(JSONKey.auth_key.toString(), sessionKey); jResponse.put(JSONKey.user_info.toString(), user.toJSONObject()); writer.print(jResponse.toString()); } else { writer.print(Utility.generalErrorMessage(ResponseCode.email_doesnt_exist.toString(), "Email address not found")); } }
From source file:com.neu.edu.servlet.CSVController.java
@Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mv = new ModelAndView(); String action = request.getParameter("action"); if (action.equals("insert")) { int result = salesorderDAO.addToDb(request); if (result > 0) { // RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/views/addBooksSuccess.jsp"); //rd.forward(request, response); String SalesOrderIDlist[] = request.getParameterValues("SalesOrderID"); HttpSession session = request.getSession(); session.setAttribute("count2", SalesOrderIDlist.length); mv.addObject("count2", SalesOrderIDlist.length); mv.setViewName("index"); }/*from w w w . j a v a 2s . co m*/ } else { ArrayList<SalesOrder> retVal = salesorderDAO.getAllOrders(); mv.addObject("retVal", retVal); mv.setViewName("index"); } return mv; }
From source file:org.davidmendoza.esu.web.InicioController.java
@RequestMapping(value = "/inicio/{anio}/{trimestre}/{leccion}/{dia}") public String inicio(Model model, @ModelAttribute Inicio inicio, HttpSession session) { session.setAttribute("anio", inicio.getAnio()); session.setAttribute("trimestre", inicio.getTrimestre()); session.setAttribute("leccion", inicio.getLeccion()); session.setAttribute("dia", inicio.getDia()); log.info("Anio: {} | Trimestre: {} | Leccion: {} | Dia: {}", new Object[] { inicio.getAnio(), inicio.getTrimestre(), inicio.getLeccion(), inicio.getDia() }); inicio = inicioService.inicio(inicio); model.addAttribute("inicio", inicio); return "inicio/inicio"; }
From source file:org.openxdata.server.servlet.FormSaveServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {// w w w.j a v a 2 s.c om String filecontents = null; CommonsMultipartResolver multipartResover = new CommonsMultipartResolver(/*this.getServletContext()*/); if (multipartResover.isMultipart(request)) { MultipartHttpServletRequest multipartRequest = multipartResover.resolveMultipart(request); filecontents = multipartRequest.getParameter("filecontents"); if (filecontents == null || filecontents.trim().length() == 0) return; } String filename = "filename.xml"; if (request.getParameter("filename") != null) { filename = request.getParameter("filename") + ".xml"; filename = filename.replace(" ", "-"); } HttpSession session = request.getSession(); session.setAttribute(KEY_FILE_NAME, filename); session.setAttribute(KEY_FILE_CONTENTS, filecontents); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.slc.sli.dashboard.web.interceptor.SessionCheckInterceptor.java
/** * Prehandle performs a session check on all incoming requests to ensure a user with an active spring security session, * is still authenticated against the api. *//*from w ww . j ava2 s . c o m*/ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String token = SecurityUtil.getToken(); JsonObject json = restClient.sessionCheck(token); // If the user is not authenticated, expire the cookie and set oauth_token to null if (!json.get(Constants.ATTR_AUTHENTICATED).getAsBoolean()) { SecurityContextHolder.getContext().setAuthentication(null); HttpSession session = request.getSession(); session.setAttribute(SLIAuthenticationEntryPoint.OAUTH_TOKEN, null); for (Cookie c : request.getCookies()) { if (c.getName().equals(SLIAuthenticationEntryPoint.DASHBOARD_COOKIE)) { c.setMaxAge(0); } } // Only redirect if not error page if (!(request.getServletPath().equalsIgnoreCase(ErrorController.EXCEPTION_URL) || request.getServletPath().equalsIgnoreCase(ErrorController.TEST_EXCEPTION_URL))) { response.sendRedirect(request.getRequestURI()); return false; } } return true; }