List of usage examples for javax.servlet.http HttpSession setAttribute
public void setAttribute(String name, Object value);
From source file:com.leapfrog.springFramework.Controller.LoginController.java
@RequestMapping(value = "/loggedIn", method = RequestMethod.POST) public String LoginUser(@RequestParam Map<String, String> parVal, HttpServletRequest request) { ModelAndView mv = new ModelAndView(); String username = parVal.get("username"); String password = parVal.get("password"); User user = dao.checkUsername(username, password); if (user != null) { HttpSession session = request.getSession(true); session.setAttribute("USER", user); session.setAttribute("user", user.getUsername()); session.setAttribute("ROLE", user.getRole()); //To remove login msg from discuss forum session.removeAttribute("loginMsg"); return "redirect:" + "/user"; }// w ww.j a v a2 s . co m return "redirect:" + "/userlogin"; }
From source file:com.tsg.cms.BlogPostController.java
@RequestMapping(value = "/taggedPostsDisplay/{tag}", method = RequestMethod.GET) public String getPostsByTagDisplay(@PathVariable("tag") String tag, Map<String, Object> model, HttpSession session) { model.put("tag", tag); session.setAttribute("page", "postsByTag"); session.setAttribute("js_page", "postsByTag.js"); return "home"; }
From source file:com.mycompany.memegenerator.FileUpload.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w. ja v a 2 s . c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (ServletFileUpload.isMultipartContent(request)) { try { List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { String name = new File(item.getName()).getName(); byte[] byteImage = item.get(); uploadImage = ImageIO.read(new ByteArrayInputStream(byteImage)); //ImageIO.write(uploadImage, "jpg", new File("C:\\uploads","snap.jpg")); // get session HttpSession session = request.getSession(); session.setAttribute("byteImage", byteImage); session.setAttribute("uploadImage", uploadImage); } } //File uploaded successfully request.setAttribute("message", "File Uploaded Successfully"); } catch (Exception ex) { request.setAttribute("message", "File Upload Failed due to " + ex); } } else { request.setAttribute("message", "Sorry this Servlet only handles file upload request"); } request.getRequestDispatcher("/index.jsp").forward(request, response); }
From source file:br.com.painel.controller.LoginController.java
@RequestMapping("efetuaLogin") public String efetuaLogin(Login login, HttpSession session, Model model) { if (new UsuarioDAO().consultarUsuario(login)) { session.setAttribute("usuarioLogado", login); return "index"; }//from ww w . jav a 2 s.c om model.addAttribute("retorno", "<div class='alert alert-danger'>usuario ou senha invalida</div>"); return "login"; }
From source file:Controller.login.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* ww w . j ava 2 s . c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); response.setContentType("text/html"); PrintWriter out = response.getWriter(); String email = request.getParameter("inputEmail"); String password = request.getParameter("inputPassword"); String remember = request.getParameter("remember"); System.out.println("remember ne mnow " + email); LoginImplementation loginCheckObject = new LoginImplementation(); JSONObject userData = (loginCheckObject.loginNow(email, password, remember)); System.out.println(userData); if (userData.has("error")) { RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); request.setAttribute("loginError", "error"); rd.include(request, response); } else { if ("yes".equals(remember)) { System.out.println("apples"); HttpSession session = request.getSession(); session.setAttribute("user", userData); //setting session to expiry in 30 mins session.setMaxInactiveInterval(30 * 60); Cookie userName = new Cookie("user", email); userName.setMaxAge(30 * 60); response.addCookie(userName); } request.setAttribute("userData", userData); RequestDispatcher rd = request.getRequestDispatcher("views/home.jsp"); rd.forward(request, response); return; } out.close(); }
From source file:jp.co.opentone.bsol.framework.web.filter.FeedAuthenticationFilter.java
private void storeAuthenticateUser(HttpServletRequest request, HttpServletResponse response, AuthUser user) { HttpSession session = request.getSession(); if (session != null) { session.setAttribute(KEY_AUTH_USER, user); }/*from w w w.j av a 2s.c o m*/ }
From source file:com.goodhuddle.huddle.web.site.PageController.java
@RequestMapping(value = "/page/preview", method = RequestMethod.POST) @ResponseBody// w ww.j a v a 2s. c o m public void savePagePreview(@RequestBody UpdatePageRequest page, HttpSession session) { log.info("Saving page preview"); session.setAttribute("huddle.page.preview", page); }
From source file:org.shredzone.commons.captcha.impl.DefaultCaptchaService.java
/** * Sets the captcha position./* w ww .ja v a 2s. c om*/ * * @param session * {@link HttpSession} * @param pos * captcha position to store */ private void setCaptchaPosition(HttpSession session, int pos) { session.setAttribute(CAPTCHA_NAME, pos); }
From source file:org.shredzone.commons.captcha.impl.DefaultCaptchaService.java
/** * Sets the position of the last click./*w ww. jav a 2 s. c o m*/ * * @param session * {@link HttpSession} * @param pos * position of the last click */ private void setLastclickPosition(HttpSession session, int pos) { session.setAttribute(LASTCLICK_NAME, pos); }
From source file:es.uma.inftel.blog.servlet.RegistroServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request/* w w w. j ava 2 s.c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); String username = request.getParameter("username"); String password = request.getParameter("password"); RegistroViewFacade registroViewFacade = new RegistroViewFacade(postFacade); RequestDispatcher registroRequestDispatcher = request.getRequestDispatcher("registro.jsp"); if (username == null && password == null) { request.setAttribute("registroView", registroViewFacade.createView(false)); registroRequestDispatcher.forward(request, response); return; } String email = request.getParameter("email"); Part filePart = request.getPart("avatar"); InputStream inputStream = filePart.getInputStream(); byte[] avatar = IOUtils.toByteArray(inputStream); Usuario usuario = registrarUsuario(username, password, email, avatar); if (usuario == null) { request.setAttribute("registroView", registroViewFacade.createView(true)); registroRequestDispatcher.forward(request, response); } else { HttpSession session = request.getSession(); session.setAttribute("usuario", usuario); response.sendRedirect("index"); } }