List of usage examples for javax.servlet.http HttpSession setAttribute
public void setAttribute(String name, Object value);
From source file:org.openmrs.web.controller.encounter.EncounterRoleFormController.java
private void purgeEncounterRole(HttpSession session, EncounterRole encounterRole, EncounterService service) { try {/*from ww w .j a v a 2s . com*/ service.purgeEncounterRole(encounterRole); session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "EncounterRole.purgedSuccessfully"); } catch (DataIntegrityViolationException e) { session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.object.inuse.cannot.purge"); } catch (APIException e) { session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.general: " + e.getLocalizedMessage()); } }
From source file:com.trailmagic.image.ui.ImageTag.java
public int doStartTag() throws JspException { StringBuffer html = new StringBuffer(); ImageManifestation mf;//from w ww.j a v a 2 s . c o m try { HttpServletRequest req = (HttpServletRequest) pageContext.getRequest(); // XXX: maybe this should be a parameter of the tag instead? // XXX: this is sort of a kludge for setting a default label String defaultLabel = req.getParameter(DEFAULT_LABEL_ATTR); HttpSession session = req.getSession(); if (defaultLabel != null) { session.setAttribute(DEFAULT_LABEL_ATTR, defaultLabel); } // XXX: end kludge String size = req.getParameter(SIZE_ATTR); String originalp = req.getParameter("original"); if (size != null) { mf = WebSupport.getMFBySize(m_image, Integer.parseInt(size), Boolean.parseBoolean(originalp)); } else { // get label by precedence: req param, tag spec, sess attr String label = req.getParameter(LABEL_ATTR); if (label == null) { label = m_sizeLabel; } if (label == null) { label = (String) session.getAttribute(DEFAULT_LABEL_ATTR); } if (label != null) { mf = WebSupport.getMFByLabel(m_image, label); } else { mf = WebSupport.getDefaultMF((User) pageContext.findAttribute(USER_ATTR), m_image); } } if (mf != null) { // XXX: resume kludge pageContext.setAttribute("currentLabel", getLabel(mf)); // XXX: end kludge // XXX: end kludge html.append("<img src=\""); //XXX: yeek? /* LinkHelper helper = new LinkHelper((HttpServletRequest)pageContext.getRequest()); */ WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(pageContext.getServletContext()); LinkHelper helper = (LinkHelper) ctx.getBean("linkHelper"); html.append(helper.getImageMFUrl((HttpServletRequest) pageContext.getRequest(), mf)); html.append("\" height=\""); html.append(mf.getHeight()); html.append("\" width=\""); html.append(mf.getWidth()); html.append("\" alt=\""); if (m_alt != null) { html.append(m_alt); } else if (m_image.getCaption() != null) { html.append(Util.escapeXml(m_image.getCaption())); } else { html.append(Util.escapeXml(m_image.getDisplayName())); } html.append("\" class=\""); if (mf.getWidth() > mf.getHeight()) { html.append("landscape"); } else { html.append("portrait"); } if (m_cssClass != null) { html.append(" "); html.append(m_cssClass); } html.append("\"/>"); } else { html.append("No manifestations found for the specified " + "image."); } pageContext.getOut().write(html.toString()); return SKIP_BODY; } catch (IOException e) { throw new JspException(e); } }
From source file:org.hdiv.web.servlet.tags.form.AbstractHtmlElementTagTests.java
private void initStateCache(HttpSession session) { IStateCache cache = (IStateCache) this.hdivContext.getBean("cache"); String cacheName = (String) this.hdivContext.getBean("cacheName"); session.setAttribute((cacheName == null) ? Constants.CACHE_NAME : cacheName, cache); }
From source file:com.sbu.controller.Feed_Personal_Startup_View_Controller.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); Startup User = new Startup(); List<Member1> members = new ArrayList(); int counter = 1; HttpSession session = request.getSession(); User = (Startup) request.getSession().getAttribute("User"); //members= (ArrayList<Member1>) request.getSession().getAttribute("members"); members = memberService.getMemberByStartupId(User.getIdStartup()); session.setAttribute("SearchQueries", User); session.setAttribute("members", members); session.setAttribute("counter", counter); //request.getRequestDispatcher("EmployeeTest.jsp").forward(request, response); request.getRequestDispatcher("/Personal_Startup.jsp").forward(request, response); }
From source file:miage.ecom.web.controller.CategoryController.java
@RequestMapping(value = "/categories/{categoryId}", method = RequestMethod.GET) public String category(Model model, HttpSession session, @PathVariable("categoryId") Integer categoryId) { CartBean cart;//from w w w. j av a 2s. c o m if (session.getAttribute("cart") == null) { cart = new CartBean(); } else { cart = (CartBean) session.getAttribute("cart"); session.setAttribute("cart", cart); } model.addAttribute("cartTotalValue", ecomBeanFrontLocal.getTotalValue(cart)); model.addAttribute("nbProducts", ecomBeanFrontLocal.getCartContents(cart).size()); List<Category> categories = categoryFacade.findAll(); model.addAttribute("categories", categories); model.addAttribute("category", categoryFacade.find(categoryId)); model.addAttribute("products", productFacadeLocal.findProductsByCategory(categoryId)); return "category"; }
From source file:controller.servlet.Upload.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from www . j a va2 s . co 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 { // Subida de los ficheros al sistema. UploadedFile uF; UploadedFileDaoImpl uFD = new UploadedFileDaoImpl(); int numberOfCsvFiles = 0; int numberOfNotCsvFiles = 0; for (Part part : request.getParts()) { if (part.getName().equals("file")) { try (InputStream is = request.getPart(part.getName()).getInputStream()) { int i = is.available(); byte[] b = new byte[i]; if (b.length == 0) { break; } is.read(b); String fileName = obtenerNombreFichero(part); String extension = FilenameUtils.getExtension(fileName); String path = this.getServletContext().getRealPath(""); String ruta = path + File.separator + Path.UPLOADEDFILES_FOLDER + File.separator + fileName; File directorio = new File(path + File.separator + Path.UPLOADEDFILES_FOLDER); if (!directorio.exists()) { directorio.mkdirs(); } // Se sube el fichero en caso de ser zip o csv. if (extension.equals(Path.CSV_EXTENSION) || extension.equals(Path.ZIP_EXTENSION)) { try (FileOutputStream os = new FileOutputStream(ruta)) { os.write(b); } if (extension.equals(Path.CSV_EXTENSION)) { numberOfCsvFiles++; } } else { numberOfNotCsvFiles++; } // Extraccin de los ficheros incluidos en el zip. if (extension.equals(Path.ZIP_EXTENSION)) { ZipInputStream zis = new ZipInputStream( new FileInputStream(directorio + File.separator + fileName)); ZipEntry eachFile; while (null != (eachFile = zis.getNextEntry())) { File newFile = new File(directorio + File.separator + eachFile.getName()); // Se guardan los csv. if (FilenameUtils.getExtension(directorio + File.separator + eachFile.getName()) .equals(Path.CSV_EXTENSION)) { numberOfCsvFiles++; try (FileOutputStream fos = new FileOutputStream(newFile)) { int len; byte[] buffer = new byte[1024]; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } } zis.closeEntry(); // Insertar en BD uF = new UploadedFile(0, eachFile.getName(), new java.sql.Date(new Date().getTime()), false, null); uFD.createFile(uF); } else { numberOfNotCsvFiles++; } } File fileToDelete = new File( path + File.separator + Path.UPLOADEDFILES_FOLDER + File.separator + fileName); fileToDelete.delete(); } else { // Insertar en BD uF = new UploadedFile(0, fileName, new java.sql.Date(new Date().getTime()), false, null); uFD.createFile(uF); } } } } // Asignacin de valores. HttpSession session = request.getSession(true); session.setAttribute("numberOfCsvFiles", numberOfCsvFiles); session.setAttribute("numberOfNotCsvFiles", numberOfNotCsvFiles); if (numberOfCsvFiles == 0 && numberOfNotCsvFiles == 0) { session.setAttribute("error", true); } else { session.setAttribute("error", false); } processRequest(request, response); }
From source file:com.sibvisions.rad.server.security.spring.authentication.SecurityManagerPreparer.java
/** * Sets additional parameters to the session and authentication object. * //from w w w .ja v a 2s . c o m * @param pRequest the request which is used to get the current session */ public void doPrepareParameters(HttpServletRequest pRequest) { String absoluteLogoutProcessUrl = buildAbsoluteLogoutProcessUrl(pRequest); HttpSession session = pRequest.getSession(false); if (session != null) { if (session.getAttribute(JVX_SPRINGSECURITY_INITIALIZED) == null) { session.setAttribute(SpringSecurityManager.LOGOUT_PROCESS_URL, absoluteLogoutProcessUrl); session.setAttribute(JVX_SPRINGSECURITY_INITIALIZED, Boolean.TRUE); } } SecurityContext context = SecurityContextHolder.getContext(); if (context != null) { Authentication authentication = context.getAuthentication(); if (authentication != null) { if (!(authentication instanceof WrappedAuthentication)) { authentication = new WrappedAuthentication(authentication); SecurityContextHolder.getContext().setAuthentication(authentication); } if (((WrappedAuthentication) authentication).getProperty(JVX_SPRINGSECURITY_INITIALIZED) == null) { ((WrappedAuthentication) authentication).setProperty(SpringSecurityManager.LOGOUT_PROCESS_URL, absoluteLogoutProcessUrl); ((WrappedAuthentication) authentication).setProperty(JVX_SPRINGSECURITY_INITIALIZED, Boolean.TRUE); } } } }
From source file:com.lioland.harmony.web.controller.DefaultController.java
@RequestMapping(method = RequestMethod.POST, value = "/authenticate") public String authenticate(String email, String password, HttpServletRequest request) { User user = new User(); user.setEmail(email);//from w ww .j a va2 s. co m user.loadObject(); HttpSession session = request.getSession(); session.removeAttribute(Constants.SESSION_ATTR_USER); if (user.getPassword().equals(password)) { // user.setPassword(DigestUtils.sha256Hex(user.getEmail().toLowerCase())); session.setAttribute(Constants.SESSION_ATTR_USER, user); System.out.println("Authenticated: " + user.getFirstName()); } return "redirect:home"; }
From source file:net.anthonychaves.bookmarks.web.FakeLoginController.java
@RequestMapping(method = RequestMethod.POST) public String fakeLogin(HttpSession session, @RequestParam("username") String username) { EntityManager em = emf.createEntityManager(); Query q = em.createQuery("select u from User u where u.firstName = ?1").setParameter(1, username); User u = (User) q.getSingleResult(); if (u != null) { session.setAttribute("user", u); return "redirect:user"; } else {//from w w w . j a v a2s .co m return "redirect:/b/user/new"; } }
From source file:org.mzd.shap.spring.web.WorkBenchController.java
@SuppressWarnings("unchecked") protected Collection<Integer> getSessionItemIds(HttpSession session) { Object mutex = WebUtils.getSessionMutex(session); synchronized (mutex) { Object obj = session.getAttribute(SESSION_ATTR_ITEMID); if (obj == null) { obj = new TreeSet<Integer>(); session.setAttribute(SESSION_ATTR_ITEMID, obj); }/*from w w w . ja va 2 s . co m*/ return (Collection<Integer>) obj; } }