List of usage examples for javax.servlet.http HttpSession setAttribute
public void setAttribute(String name, Object value);
From source file:org.openmrs.module.appointmentscheduling.web.controller.AppointmentBlockCalendarController.java
@RequestMapping(value = "/module/appointmentscheduling/appointmentBlockCalendar", method = RequestMethod.GET) public void showForm(HttpServletRequest request, ModelMap model) throws ParseException { if (Context.isAuthenticated()) { //Set the location from the session if (request.getSession().getAttribute("chosenLocation") != null) { Location location = (Location) request.getSession().getAttribute("chosenLocation"); model.addAttribute("chosenLocation", location); }/*from ww w. j ava 2 s . c o m*/ //Set the provider from the session if (request.getSession().getAttribute("chosenProvider") != null) { Provider provider = Context.getProviderService() .getProvider((Integer) request.getSession().getAttribute("chosenProvider")); model.addAttribute("chosenProvider", provider.getProviderId()); } //Set the appointmentType from the session if (request.getSession().getAttribute("chosenType") != null) { AppointmentType appointmentType = Context.getService(AppointmentService.class) .getAppointmentType((Integer) request.getSession().getAttribute("chosenType")); model.addAttribute("chosenType", appointmentType.getAppointmentTypeId()); } //Set the date interval from the session String fromDate; String toDate; Long fromDateAsLong; Long toDateAsLong; fromDate = (String) request.getSession().getAttribute("fromDate"); toDate = (String) request.getSession().getAttribute("toDate"); Calendar cal = Context.getDateTimeFormat().getCalendar(); if (fromDate == null && toDate == null) { //In case the user loaded the page for the first time, we will set to default the time interval (1 week from today). Date startDate = OpenmrsUtil.firstSecondOfDay(new Date()); fromDate = Context.getDateTimeFormat().format(startDate); fromDateAsLong = startDate.getTime(); cal.setTime(OpenmrsUtil.getLastMomentOfDay(new Date())); cal.add(Calendar.DAY_OF_MONTH, 6); Date endDate = cal.getTime(); toDate = Context.getDateTimeFormat().format(endDate); toDateAsLong = endDate.getTime(); } else { //Session is not empty and we need to change the locale if we have to. Locale lastLocale = (Locale) request.getSession().getAttribute("lastLocale"); Locale currentLocale = Context.getLocale(); Date startDate; Date endDate; //check if the last locale equals to the current locale if (lastLocale != null && lastLocale.toString().compareTo(currentLocale.toString()) != 0) { //if the locals are different startDate = OpenmrsUtil.getDateTimeFormat(lastLocale).parse(fromDate); endDate = OpenmrsUtil.getDateTimeFormat(lastLocale).parse(toDate); fromDate = Context.getDateTimeFormat().format(startDate); toDate = Context.getDateTimeFormat().format(endDate); fromDateAsLong = startDate.getTime(); toDateAsLong = endDate.getTime(); } else { startDate = OpenmrsUtil.getDateTimeFormat(currentLocale).parse(fromDate); endDate = OpenmrsUtil.getDateTimeFormat(currentLocale).parse(toDate); fromDateAsLong = startDate.getTime(); toDateAsLong = endDate.getTime(); } } //Update session variables - this will be updated in every locale change. HttpSession httpSession = request.getSession(); httpSession.setAttribute("fromDate", fromDate); httpSession.setAttribute("toDate", toDate); httpSession.setAttribute("lastLocale", Context.getLocale()); //Update model variables - what the page shows. model.addAttribute("fromDate", fromDateAsLong); model.addAttribute("toDate", toDateAsLong); } }
From source file:com.mkmeier.quickerbooks.ProcessSquare.java
private void showForm(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { //Load Account Options Map<String, List<QbAccount>> accountLists = getAccountLists(); HttpSession session = request.getSession(true); session.setAttribute("lists", accountLists); RequestDispatcher rd = request.getRequestDispatcher("SquareProcessor.jsp"); rd.forward(request, response);/*from w ww .j a v a 2s.c o m*/ }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.frontdesk.web.actions.EditOutputWriterAction.java
/** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed./* ww w.j a v a2s .com*/ * * @param mapping The ActionMapping used to select this instance * @param actionForm The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception Exception if the application business logic throws * an exception */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes and parameters we will need HttpSession session = request.getSession(); if ("request".equals(mapping.getScope())) { request.setAttribute(mapping.getAttribute(), form); } else { session.setAttribute(mapping.getAttribute(), form); } if (!isExperimenter(session)) return (mapping.findForward("login_fail")); int experimenterId = (Integer) session.getAttribute(JMConstants.EXPERIMENTER_KEY); List<LabelValueBean> sessions = ControlServ.dbw.getExperimentsByExperimenterId(experimenterId); session.setAttribute("sessions", sessions); return mapping.findForward("success"); }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.frontdesk.web.actions.EditSaveConfigAction.java
/** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed./* w w w . ja v a2 s. co m*/ * * @param mapping The ActionMapping used to select this instance * @param actionForm The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception Exception if the application business logic throws * an exception */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need HttpSession session = request.getSession(); if ("request".equals(mapping.getScope())) { request.setAttribute(mapping.getAttribute(), form); } else { session.setAttribute(mapping.getAttribute(), form); } if (!isExperimenter(session)) return (mapping.findForward("login_fail")); SaveConfigForm saveForm = (SaveConfigForm) form; SessionBean sessionBean = (SessionBean) session.getAttribute("sessionBean"); String relativeSavePath = (String) session.getAttribute("relativeSavePath"); saveForm.setRelativeSavePath(relativeSavePath); return (mapping.findForward("success")); }
From source file:net.firejack.platform.utils.SessionManager.java
/** * @param user// www .jav a2 s .co m * @param httpSession */ public void addUserToSession(IUserInfoProvider user, HttpSession httpSession) { HttpSession session = sessionsMap.get(httpSession.getId()); if (session == null) { session = httpSession; sessionsMap.putIfAbsent(httpSession.getId(), session); } session.setAttribute(SESSION_USER_INFO_PARAM, user); }
From source file:org.openmrs.module.drawing.web.controller.ManageTemplatesController.java
@RequestMapping(value = "/module/drawing/manageTemplates", method = RequestMethod.POST) public void manage(@RequestParam(value = "templateName", required = false) String templateName, @RequestParam(value = "template", required = true) MultipartFile file, ModelMap model, HttpSession session) { model.addAttribute("encodedTemplateNames", DrawingUtil.getAllTemplateNames()); if (file == null || file.getSize() == 0) { session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Please Fill All The Fields"); return;/* www .j a v a 2 s . c o m*/ } else if (!DrawingUtil.isImage(file.getOriginalFilename())) { session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "File Format Not Supported"); return; } if (StringUtils.isBlank(templateName)) templateName = file.getOriginalFilename(); else templateName = templateName + "." + DrawingUtil.getExtension(file.getOriginalFilename()); try { BufferedImage bi = ImageIO.read(new ByteArrayInputStream(file.getBytes())); Boolean saved = DrawingUtil.saveFile(templateName, bi); if (saved) { session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Template Saved"); model.addAttribute("encodedTemplateNames", DrawingUtil.getAllTemplateNames()); } else session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Error Saving Template"); } catch (IOException e) { session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Unable To Save Uploaded File"); log.error("Unable to read uploadedFile", e); } }
From source file:com.hp.security.jauth.admin.controller.BaseController.java
@RequestMapping("loginProcess") public void loginProcess(HttpServletRequest request, HttpServletResponse response) throws IOException, TemplateException { String userId = request.getParameter("userId"); String password = request.getParameter("password"); AssociateUser user = associateUserService.findByUserId(userId); if (null != user && MD5.getInstance().getMD5ofStr(password).equalsIgnoreCase(user.getPassword())) { HttpSession session = request.getSession(); session.setAttribute(SystemInit.sessionID, userId); response.sendRedirect(request.getContextPath() + "/jauth/index"); } else {/*from w w w . j a v a2 s . c o m*/ request.setAttribute("error", "Sorry, username or password is not correct!"); login(request, response); } }
From source file:com.tsg.cms.BlogPostController.java
@RequestMapping(value = "/link/{titleNumber}", method = RequestMethod.GET) public String getLinkedPost(@PathVariable("titleNumber") String titleNumber, Map<String, Object> model, HttpSession session) { int id = blogPostDao.getBlogPostByTitleNumber(titleNumber).getBlogPost().getPostId(); model.put("id", id); session.setAttribute("page", "singlePost"); session.setAttribute("js_page", "singlePost.js"); return "home"; }
From source file:com.sfs.ucm.security.Authenticator.java
/** * logout action/*from w w w .j a v a2 s . c om*/ */ public void logout() { HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext() .getSession(false); if (session != null) { session.setAttribute("USERID", null); session.invalidate(); } }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.frontdesk.web.actions.TerminateSessionAction.java
/** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed./*from ww w . j a va 2s .c o m*/ * * @param mapping The ActionMapping used to select this instance * @param actionForm The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception Exception if the application business logic throws * an exception */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need HttpSession session = request.getSession(); if ("request".equals(mapping.getScope())) { request.setAttribute(mapping.getAttribute(), form); } else { session.setAttribute(mapping.getAttribute(), form); } if (!isExperimenter(session)) return (mapping.findForward("login_fail")); SessionBean sessionBean = (SessionBean) session.getAttribute("sessionBean"); //sessionBean.stopSession(); DEPRECATED ActionMessages msg = new ActionMessages(); msg.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("launch.terminated")); saveMessages(request, msg); return (mapping.findForward("success")); }