List of usage examples for javax.servlet.http HttpSession setAttribute
public void setAttribute(String name, Object value);
From source file:CommonServlets.EditUser.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String email = null, userName = null, job = null, address = null, password = null, img = null, role = null; BigDecimal creditLimit = new BigDecimal(0); try {/*from w ww . j a v a 2 s .c o m*/ // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request List<FileItem> items = upload.parseRequest(request); Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem item = iter.next(); if (item.isFormField()) { //processFormField(item); String name = item.getFieldName(); String value = item.getString(); if (name.equalsIgnoreCase("email")) { email = value; } else if (name.equalsIgnoreCase("userName")) { userName = value; } else if (name.equalsIgnoreCase("creditLimit")) { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setGroupingSeparator(','); symbols.setDecimalSeparator('.'); String pattern = "#,##0.0#"; DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols); decimalFormat.setParseBigDecimal(true); creditLimit = (BigDecimal) decimalFormat.parse(value); } else if (name.equalsIgnoreCase("job")) { job = value; } else if (name.equalsIgnoreCase("address")) { address = value; } else if (name.equalsIgnoreCase("password")) { password = value; } } else if (!item.isFormField() && !item.getName().equals("")) { System.out.println(new File(AddProduct.class.getClassLoader().getResource("").getPath() .replace("%20", " ") .substring(0, AddProduct.class.getClassLoader().getResource("").getPath() .replace("%20", " ").length() - 27) + "/web/Resources/users_pics/" + item.getName())); item.write(new File(AddProduct.class.getClassLoader().getResource("").getPath() .replace("%20", " ") .substring(0, AddProduct.class.getClassLoader().getResource("").getPath() .replace("%20", " ").length() - 27) + "/web/Resources/users_pics/" + item.getName())); img = item.getName(); } } User u = new User(email, userName, password, creditLimit, job, address, img, role); controlServlet.editUserDate(u); HttpSession session = request.getSession(true); session.setAttribute("done", "1"); ControlServlet c = new ControlServlet(); User myUser = c.getUser(userName); session.setAttribute("user", myUser); response.sendRedirect("UserHome.jsp"); } catch (Exception ex) { Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:dicky.controlleruser.CartController.java
@RequestMapping(value = "delete/{index}", method = RequestMethod.GET) public String delete(@PathVariable("index") int index, HttpSession session) { List<Item> cart = (List<Item>) session.getAttribute("cart"); cart.remove(index);//from w w w .j a v a 2 s . c om session.setAttribute("cart", cart); return "redirect:/cart.html"; }
From source file:csns.web.controller.RubricController.java
@RequestMapping("/department/{dept}/rubric/search") public String search(@RequestParam String term, HttpSession session) { List<Rubric> rubrics = rubricDao.searchRubrics(term, -1); session.setAttribute("rubricSearchTerm", term); session.setAttribute("rubricSearchResults", rubrics); return "redirect:list#search"; }
From source file:info.raack.appliancelabeler.security.HttpSessionAndDatabaseOAuthRemeberMeServices.java
public void rememberTokens(Map<String, OAuthConsumerToken> tokens, HttpServletRequest request, HttpServletResponse response) {/*from w w w . ja v a 2 s . c om*/ // put tokens into session String email = ""; HttpSession session = request.getSession(false); if (session != null) { session.setAttribute(REMEMBERED_TOKENS_KEY, tokens); email = (String) session.getAttribute(EMAIL_ATTRIBUTE); } // put tokens into database Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null && auth.isAuthenticated()) { String userId = null; if (auth instanceof RememberMeAuthenticationToken) { Object principal = auth.getPrincipal(); if (principal instanceof OAuthUserDetails) { userId = ((OAuthUserDetails) principal).getUsername(); } else if (principal instanceof String) { userId = (String) auth.getPrincipal(); } } else if (auth instanceof OAuthAutomaticAuthenticationToken) { // user is already logged in via spring security userId = (String) auth.getPrincipal(); } logger.debug("Saving oauth tokens to database"); if (userId != null) { dataService.saveOAuthTokensForUserId(userId, email, tokens); } } }
From source file:org.openmrs.module.laboratory.web.controller.main.MainController.java
@RequestMapping(method = RequestMethod.GET) public String firstView(HttpServletRequest request, Model model) { HttpSession session = request.getSession(); Map<Concept, Set<Concept>> testTreeMap = generateTestTreeMap(); logger.info("Test tree: " + testTreeMap); session.setAttribute(LaboratoryConstants.SESSION_TEST_TREE_MAP, testTreeMap); return "/module/laboratory/main/main"; }
From source file:org.openmrs.web.controller.report.ReportSchemaXmlFormController.java
/** * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) *///from w w w . jav a2 s . c o m @Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object commandObject, BindException errors) throws Exception { ReportSchemaXml reportSchemaXml = (ReportSchemaXml) commandObject; ReportService reportService = (ReportService) Context.getService(ReportService.class); try { // create a new object out of their xml in order to verify xml and copy out the id/name/desc ReportSchema schema = reportService.getReportSchema(reportSchemaXml); // if the user changed the reportSchemaId to create a new one, create a new object here // so hibernate doesn't complain if (reportSchemaXml.getReportSchemaId() != null && !schema.getReportSchemaId().equals(reportSchemaXml.getReportSchemaId())) { String xml = reportSchemaXml.getXml(); reportSchemaXml = new ReportSchemaXml(); reportSchemaXml.setXml(xml); } reportSchemaXml.populateFromReportSchema(schema); // save the xml to the database reportService.saveReportSchemaXml(reportSchemaXml); } catch (Exception ex) { log.warn("Exception building ReportSchema from XML", ex); if (ex.getCause() != null) { Throwable temp = ex.getCause(); while (temp.getCause() != null) temp = temp.getCause(); errors.rejectValue("xml", temp.getMessage()); } else { StringBuilder sb = new StringBuilder(); sb.append("Invalid XML content<br/>"); sb.append(ex).append("<br/>"); for (StackTraceElement e : ex.getStackTrace()) sb.append(e.toString()).append("<br/>"); errors.rejectValue("xml", sb.toString()); } return showForm(request, response, errors); } HttpSession httpSession = request.getSession(); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "reportingcompatibility.Report.manageSchema.saved"); return new ModelAndView(new RedirectView(getSuccessView())); }
From source file:de.laures.cewolf.storage.AbstractSessionStorage.java
protected String storeChartImage(ChartImage cid, HttpSession session) throws CewolfException { final String sessionKey = getKey(cid); synchronized (session) { session.setAttribute(sessionKey, getCacheObject(cid)); }/* www. j a va 2 s . co m*/ return sessionKey; }
From source file:cs425.yogastudio.controller.SignupController.java
@RequestMapping(value = "/addCustomer", method = RequestMethod.POST) public String addCustomer(String firstname, String lastname, String email, String username, String password, String state, String zip, String street, String city, Model model, HttpSession session, @RequestParam("file") MultipartFile file) { if (checkUsername(username)) { session.setAttribute("nonUniqueMessage", null); Customer newCustomer = new Customer(firstname, lastname, email, username, password); Address newAddress = new Address(state, zip, street, city); // ShoppingCart shoppingCart = new ShoppingCart(newCustomer); if (!file.isEmpty()) { try { newCustomer.setProductImage(file.getBytes()); } catch (IOException e) { e.printStackTrace();/*w w w . j a va2s. c o m*/ } } newCustomer.addAddress(newAddress); customerService.addCustomer(newCustomer); //model.addAttribute("newcustomer", newCustomer); session.setAttribute("added", newCustomer.getFirstName()); return "redirect:/signUpSuccess"; } else { session.setAttribute("nonUniqueMessage", "username already exists, try another one"); return "redirect:/customerSignup"; } }
From source file:mx.edu.um.mateo.general.utils.Ambiente.java
public void actualizaSesion(HttpSession session, Usuario usuario) { log.debug("Actualizando sesion"); if (usuario != null) { if (usuario.getEjercicio() != null) { session.setAttribute("ejercicioLabel", usuario.getEjercicio().getId().getIdEjercicio()); }//w w w.j ava 2s . c om session.setAttribute("organizacionLabel", usuario.getEmpresa().getOrganizacion().getNombre()); session.setAttribute("empresaLabel", usuario.getEmpresa().getNombre()); session.setAttribute("almacenLabel", usuario.getAlmacen().getNombre()); session.setAttribute("organizacionId", usuario.getEmpresa().getOrganizacion().getId()); session.setAttribute("empresaId", usuario.getEmpresa().getId()); session.setAttribute("almacenId", usuario.getAlmacen().getId()); session.setAttribute("ejercicioId", usuario.getEjercicio().getId().getIdEjercicio()); } }
From source file:org.openmrs.module.populatingactivelists.web.controller.AllergiesMigrationController.java
@RequestMapping(value = "/module/obsconverter/allergiesmigration", method = RequestMethod.POST) public void afterPageSubmission(@RequestParam("allergiesAddedConceptID") Integer allergiesAddedConcept, @RequestParam("allergiesRemovedConceptID") Integer allergiesRemovedConcept, HttpSession httpSession) { int count = super.afterPageSubmission(allergiesAddedConcept, allergiesRemovedConcept, this); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "All active observations are migrated to active problems list successfully. total migrated observations: " + count);/*from w ww . ja v a 2 s. c o m*/ }