Example usage for javax.servlet.http HttpSession setAttribute

List of usage examples for javax.servlet.http HttpSession setAttribute

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession setAttribute.

Prototype

public void setAttribute(String name, Object value);

Source Link

Document

Binds an object to this session, using the name specified.

Usage

From source file:com.epam.trade.storefront.controllers.pages.ProductPageController.java

@RequestMapping(value = "/showPhoneNumber", method = RequestMethod.GET)
public @ResponseBody String showPhoneNumber(@RequestParam("advertisementCode") final String advertisementCode,
        final HttpServletRequest request) {
    advertisementFacade.addViewedPhoneNumbersAdvertisement(advertisementCode);
    final String contactNumber = advertisementFacade.getContactNumberByAdvertisementCode(advertisementCode);

    final HttpSession session = request.getSession();
    session.setAttribute("phoneNumberForCode", advertisementCode);
    session.setAttribute("openedPhoneNumber", contactNumber);

    return contactNumber;
}

From source file:org.openmrs.module.sdmxhdintegration.web.controller.ConfigController.java

@RequestMapping(method = RequestMethod.POST)
public String doPost(HttpSession session, @RequestParam String messageUploadDir) {

    AdministrationService as = Context.getAdministrationService();

    GlobalProperty gp = as.getGlobalPropertyObject("sdmxhdintegration.messageUploadDir");
    gp.setPropertyValue(messageUploadDir);
    as.saveGlobalProperty(gp);//from   www  .  ja va 2s . c o  m

    session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Configuration saved");

    return "redirect:config.form";
}

From source file:org.openmrs.web.controller.form.FieldTypeFormController.java

/**
 * The onSubmit function receives the form/command object that was modified by the input form
 * and saves it to the db//from w w w.j  a  v  a2s .  c o m
 *
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 */
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj,
        BindException errors) throws Exception {

    HttpSession httpSession = request.getSession();

    String view = getFormView();

    if (Context.isAuthenticated()) {
        FieldType fieldType = (FieldType) obj;
        Context.getFormService().saveFieldType(fieldType);
        view = getSuccessView();
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "FieldType.saved");
    }

    return new ModelAndView(new RedirectView(view));
}

From source file:be.fedict.eid.idp.protocol.ws_federation.AbstractWSFederationProtocolService.java

private void storeWtrealm(String wtrealm, String wreply, HttpServletRequest request) {
    HttpSession httpSession = request.getSession();
    httpSession.setAttribute(WTREALM_SESSION_ATTRIBUTE, wtrealm);
    httpSession.setAttribute(WREPLY_SESSION_ATTRIBUTE, wreply);
}

From source file:ilearn.orb.controller.LogInOutController.java

@RequestMapping(value = "/login", method = RequestMethod.POST)
public ModelAndView login(@RequestParam String username, @RequestParam String pass, ModelMap modelMap,
        HttpServletRequest request, HttpSession session) {
    ModelAndView model = new ModelAndView();

    try {/*from www.  ja v  a  2 s. co  m*/
        String jsonTokens = UserServices.getToken(username, pass);
        TokenPack tp = new Gson().fromJson(jsonTokens, TokenPack.class);
        String token = tp.getAuth();
        session.setAttribute("username", username);
        session.setAttribute("auth", token);

        String json = UserServices.getDetails(username);
        session.setAttribute("id", (new JsonParser().parse(json).getAsJsonObject()).get("id").toString());

        model.setViewName("redirect:/");
    } catch (Exception e) {
        model.setViewName("login");
        int t = e.getMessage().indexOf('?');
        modelMap.addAttribute("error", e.getMessage().substring(0, t));
    }
    return model;
}

From source file:com.skilrock.lms.web.accMgmt.common.RetailerPaymentSubmit.java

public String retailerPayment() throws Exception {
    HttpSession session = null;
    session = getRequest().getSession();
    session.setAttribute("Receipt_Id", null);
    UserInfoBean userInfo;/*from w  w  w  .  j av a2s  . c  om*/
    try {
        if (totalAmount != cashAmnt)
            throw new LMSException(LMSErrors.RETAILER_PAYMENT_INVALIDATE_DATA_ERROR_CODE,
                    LMSErrors.RETAILER_CASH_PAYMENT_INVALIDATE_DATA_ERROR_MESSAGE);

        userInfo = (UserInfoBean) session.getAttribute("USER_INFO");
        logger.info("REQUEST_RETAILER_CASH_PAYMENT_SUBMIT-" + request.getAttribute("AUDIT_ID") + ":"
                + userInfo.getUserId());
        int agentId = userInfo.getUserId();
        String agentName = userInfo.getOrgName();
        int userOrgID = userInfo.getUserOrgId();

        RetailerPaymentSubmitHelper retailerPaymentHelper = new RetailerPaymentSubmitHelper();

        String autoGeneRecieptNoAndId = retailerPaymentHelper.retailerCashPaySubmit(orgId, "RETAILER",
                totalAmount, agentId, userOrgID, userInfo.getUserType());
        if (!autoGeneRecieptNoAndId.contains("#")) {
            addActionError(autoGeneRecieptNoAndId);
            retailerInfoMap = CommonMethods.getOrgInfoMap(userInfo.getUserOrgId(), "RETAILER");
            return ERROR;
        }
        String[] autoGeneReceipt = autoGeneRecieptNoAndId.split("#");
        String autoGeneRecieptNo = autoGeneReceipt[0];
        int id = Integer.parseInt(autoGeneReceipt[1]);
        session.setAttribute("totalPay", totalAmount);
        //session.setAttribute("orgName", orgName);
        session.setAttribute("Receipt_Id", autoGeneRecieptNo);

        GraphReportHelper graphReportHelper = new GraphReportHelper();
        graphReportHelper.createTextReportAgent(id, (String) session.getAttribute("ROOT_PATH"), userOrgID,
                agentName);

        session.removeAttribute("CASH");
    } catch (LMSException le) {

        logger.info("RESPONSE_RETAILER_CASH_PAYMENT_SUBMIT-: ErrorCode:" + le.getErrorCode() + " ErrorMessage:"
                + le.getErrorMessage());
        request.setAttribute("LMS_EXCEPTION", le.getErrorMessage());
        return "applicationException";
    } catch (Exception e) {
        logger.error("Exception", e);
        logger.info(
                "RESPONSE_RETAILER_CASH_PAYMENT_SUBMIT-: ErrorCode:" + LMSErrors.GENERAL_EXCEPTION_ERROR_CODE
                        + " ErrorMessage:" + LMSErrors.GENERAL_EXCEPTION_ERROR_MESSAGE);
        request.setAttribute("LMS_EXCEPTION", LMSErrors.GENERAL_EXCEPTION_ERROR_MESSAGE);
        return "applicationException";
    }
    return SUCCESS;

}

From source file:DateServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    HttpSession hs = request.getSession(true);

    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    pw.print("<B>");

    Date date = (Date) hs.getAttribute("date");
    if (date != null) {
        pw.print("Last access: " + date + "<br>");
    }/*from ww w .j av  a2  s.co m*/

    date = new Date();
    hs.setAttribute("date", date);
    pw.println("Current date: " + date);
}

From source file:cs544.letmegiveexam.controller.LoginController.java

@RequestMapping(value = "/welcome", method = RequestMethod.GET)
public String welcome(Model model, HttpSession session) {

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String name = auth.getName();

    if (session.getAttribute("user") == null) {
        User user = userServices.getUserByUsername(name);
        session.setAttribute("user", user);
    }//from w  w w  .  j a v a2 s. c  om
    //ModelAndView model = new ModelAndView();
    List<Subject> subjects = subjectService.getAllSubjects();

    //        for (Subject sub : subjects) {
    //            System.out.println("Subject:" + sub.getName() + "  Description:" + sub.getDescription());
    //
    //        }
    model.addAttribute("subjects", subjects);
    return "welcome";
}