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:egovframework.oe1.cms.com.web.EgovOe1MainController.java

/**
 *  view//from w  ww  .j a v a 2  s. c  o m
 * @param request
 * @param commandMap
 * @param model
 * @return   URL
 * @throws Exception
 */
@RequestMapping(value = "/cms/com/EgovOe1Menu.do")
public String viewTmpMenu(HttpServletRequest request, Map commandMap, ModelMap model) throws Exception {

    String sUrl = commandMap.get("s_url") == null ? "" : (String) commandMap.get("s_url");
    String sMenuId = commandMap.get("s_MenuId") == null ? "" : (String) commandMap.get("s_MenuId");

    if (sMenuId.equals("")) {
        sUrl = "forward:/cms/com/selectBoardMainList.do";
    } else {
        HttpSession session = request.getSession(true);
        session.setAttribute("s_MenuId", sMenuId);
    }

    return "forward:" + sUrl;
}

From source file:org.openmrs.module.dms.web.controller.main.EditUnitController.java

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(@RequestParam(value = "unitId", required = false) Integer unitId, Model model,
        HttpServletRequest request) {/*from  www.  j  av  a 2s.  c  om*/
    DmsService dmsService = Context.getService(DmsService.class);
    DmsOpdUnit dmsopdunit = new DmsOpdUnit();

    dmsopdunit = dmsService.getDmsOpd(unitId);

    String day = request.getParameter("selday");
    String starttime = request.getParameter("starttime");
    String endtime = request.getParameter("endtime");

    starttime = starttime + ":00";
    endtime = endtime + ":00";

    HttpSession httpSession = request.getSession();

    dmsopdunit.setOpdWorkingDay(day);
    dmsopdunit.setStartTime(starttime);
    dmsopdunit.setEndTime(endtime);
    dmsService.saveOrUpdateUnit(dmsopdunit);
    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "dms.edit.success");
    return "redirect:/module/dms/viewEditUnitList.form";
}

From source file:cn.vlabs.duckling.vwb.FetchToSession.java

@SuppressWarnings("unchecked")
private HashMap<String, String> getSavedParams(HttpSession session) {
    HashMap<String, String> savedParams = (HashMap<String, String>) session.getAttribute(FETCH_PARAMS);
    if (savedParams == null) {
        savedParams = new HashMap<String, String>();
        session.setAttribute(FETCH_PARAMS, savedParams);
    }/*from  w  w  w . j av  a 2 s. c  o  m*/
    return savedParams;
}

From source file:com.lm.lic.manager.service.HibernateLoginService.java

/**
 * @param username/*w ww  .  j  ava  2  s. c om*/
 * @param loggedin
 * @param user
 * @param httpSession
 */
public void makeUserLoggedIn(User user, HttpSession httpSession) {
    httpSession.setAttribute(GenUtil.LOGGED_IN_ATTRIBUTE, true);
    httpSession.setAttribute(GenUtil.ROLE_ATTRIBUTE, user.extractPrimaryRole());
    httpSession.setAttribute(GenUtil.LOGGED_IN_USER_ATTRIBUTE, user.getUsername());
    httpSession.setAttribute("user", user);
    httpSession.setAttribute("home", roleHomeFinder.findHome(user.extractPrimaryRole()));

    String userTypeRleId = findUsertypeRoleId(user);
    httpSession.setAttribute("userTypeRoleId", userTypeRleId);

    Object userTypeRoleObj = user.getMainUserTypeRoleObj();
    httpSession.setAttribute("userTypeRoleObj", userTypeRoleObj);

    httpSession.setAttribute("aclContext", aclContext);
    addLoggedinUser(user.getUsername(), httpSession);
}

From source file:com.lm.lic.manager.service.HibernateLoginService.java

/**
 * @param username//from  www  .j  av  a 2s.  c o m
 * @param loggedin
 * @param user
 * @param httpSession
 */
public void makeUserLoggedOut(User user, HttpSession httpSession) {
    httpSession.setAttribute(GenUtil.LOGGED_IN_ATTRIBUTE, false);

    httpSession.removeAttribute("user");

    httpSession.removeAttribute(GenUtil.LOGGED_IN_ATTRIBUTE);
    httpSession.removeAttribute(GenUtil.ROLE_ATTRIBUTE);
    httpSession.removeAttribute(GenUtil.LOGGED_IN_USER_ATTRIBUTE);
    httpSession.removeAttribute("user");
    httpSession.removeAttribute("home");
    httpSession.removeAttribute("userTypeRoleId");
    httpSession.removeAttribute("userTypeRoleObj");
    httpSession.removeAttribute("aclContext");

    removeLoggedinUser(user.getUsername());
}

From source file:Controllers.SeatSelectionController.java

@RequestMapping(value = "/seatselection", method = RequestMethod.POST)
protected ModelAndView getSeatSelectionPage(@RequestParam("adult") int numAdults,
        @RequestParam("senior") int numSeniors, @RequestParam("child") int numChildren,
        HttpServletRequest request) {//from  w  ww.j  a v  a  2s  .c o  m

    String contextPath = request.getContextPath();
    System.out.println("Path: " + contextPath);
    request.setAttribute("contextPath", contextPath);

    HttpSession session = request.getSession();
    int totalNumSeats = numAdults + numSeniors + numChildren;
    session.setAttribute("numAdults", numAdults);
    request.setAttribute("numAdults", numAdults);
    session.setAttribute("numSeniors", numSeniors);
    request.setAttribute("numSeniors", numSeniors);
    session.setAttribute("numChildren", numChildren);
    request.setAttribute("numChildren", numChildren);
    session.setAttribute("totalNumSeats", totalNumSeats);
    request.setAttribute("totalNumSeats", totalNumSeats);
    Showing showing = (Showing) session.getAttribute("showing");

    ModelAndView modelandview;
    String seatingLayout = showing.getTheatreRoom().getLayout();
    if (!seatingLayout.equals("")) {
        seatingLayout = seatingLayout.replaceAll(" ", "");
        String[] rowsArray = seatingLayout.split("R");
        int numColumns = rowsArray[0].replaceAll(",", "").length();
        int numRows = rowsArray.length;
        Seat[][] seatingMatrix = new Seat[numRows][numColumns];
        int seatValue = 0;

        char seatRow = 'A';
        int seatNum = 1;
        System.out.println("NumRows: " + numRows);
        System.out.println("NumColumns: " + numColumns);
        for (int rowIndex = 0; rowIndex < rowsArray.length; rowIndex++) {
            String rowLayout = rowsArray[rowIndex];
            String[] seatValuesArray = rowLayout.split(",");
            for (int seatIndex = 0; seatIndex < seatValuesArray.length; seatIndex++) {
                if (!seatValuesArray[seatIndex].equals("")) {
                    seatValue = Integer.parseInt(seatValuesArray[seatIndex]);
                }
                Seat seat = null;
                if (seatValue == 1) {
                    seat = new Seat();
                    seat.setRow(String.valueOf(seatRow));
                    seat.setSeatNumber(Integer.toString(seatNum));
                    seat.setAvailable(true);
                    seatNum++;
                }
                seatingMatrix[rowIndex][seatIndex] = seat;
            }
            seatRow = (char) (seatRow + 1);
            seatNum = 1;
        }

        // make purchased seats unavailable
        List<Ticket> purchasedTickets = ticketService.getTicketByShowing(showing);
        for (Ticket ticket : purchasedTickets) {
            char purchasedSeatRow = ticket.getSeat().getRow().charAt(0);
            int rowIndex = ((int) purchasedSeatRow) - ((int) 'A');
            // now that we have the right row seat for this seat search all of the columns for it
            for (int i = 0; i < numColumns; i++) {
                Seat seatInMatrix = seatingMatrix[rowIndex][i];
                if (seatInMatrix != null) {
                    if (seatInMatrix.getRow().equals(ticket.getSeat().getRow())
                            && seatInMatrix.getSeatNumber().equals(ticket.getSeat().getSeatNumber())) {
                        seatInMatrix.setAvailable(false);
                    }
                }
            }
        }

        // make all locked live seats unavailable
        LiveTickets ts = ticketService.getLiveTickets();
        List<Ticket> tickets = ts.getTicketsByShowing(showing);
        for (Ticket ticket : tickets) {
            Seat seat = ticket.getSeat();
            char purchasedSeatRow = seat.getRow().charAt(0);
            int rowIndex = ((int) purchasedSeatRow) - ((int) 'A');
            for (int i = 0; i < numColumns; i++) {
                Seat seatInMatrix = seatingMatrix[rowIndex][i];
                if (seatInMatrix != null) {
                    if (seatInMatrix.getRow().equals(ticket.getSeat().getRow())
                            && seatInMatrix.getSeatNumber().equals(ticket.getSeat().getSeatNumber())) {
                        seatInMatrix.setAvailable(false);
                    }
                }
            }
        }

        request.setAttribute("seatingMatrix", seatingMatrix);
        modelandview = new ModelAndView("seatselection");
    } else {
        modelandview = new ModelAndView("paymentpage");
    }
    return modelandview;
}

From source file:edu.caltechUcla.sselCassel.projects.jMarkets.frontdesk.web.actions.SaveExpRegAction.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  . j  a  va2  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);
    }

    DynaValidatorForm regForm = (DynaValidatorForm) form;

    String email = (String) regForm.get("email");
    String fname = (String) regForm.get("fname");
    String lname = (String) regForm.get("lname");
    String phone = (String) regForm.get("phone");
    String school = (String) regForm.get("school");
    String password = (String) regForm.get("password");

    String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());

    String query = "insert into jm_user values(0,'" + email + "','" + fname + "','" + lname + "','" + phone
            + "',PASSWORD('" + password + "'), 'none', '" + date + "', 0, 0," + JMConstants.EXPERIMENTER_ROLE
            + " )";

    int expId = ControlServ.dbw.registerSubject(query);

    if (expId < 0) {
        ActionMessages errors = new ActionMessages();
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.email.unique", email));
        saveErrors(request, errors);
        return (mapping.findForward("failure"));
    }

    loginExperimenter(session, expId);

    ActionMessages msg = new ActionMessages();
    msg.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("exp.reg.success"));
    saveMessages(request, msg);

    return (mapping.findForward("success"));
}

From source file:com.adito.security.LogonStateAndCache.java

public LogonStateAndCache(int startState, HttpSession session) {
    super();/*from w  w  w . j av a  2s  . c  om*/
    session.setAttribute(LOGON_STATE_MACHINE, this);
    this.setState(startState);

}

From source file:edu.cornell.mannlib.vitro.webapp.controller.json.GetEntitiesByVClass.java

@Override
protected JSONArray process() throws ServletException {
    log.debug("in getEntitiesByVClass()");
    String vclassURI = vreq.getParameter("vclassURI");
    WebappDaoFactory daos = vreq.getUnfilteredWebappDaoFactory();

    if (vclassURI == null) {
        throw new ServletException("getEntitiesByVClass(): no value for 'vclassURI' found in the HTTP request");
    }/*from  w  w  w . j a v  a2s.  com*/

    VClass vclass = daos.getVClassDao().getVClassByURI(vclassURI);
    if (vclass == null) {
        throw new ServletException("getEntitiesByVClass(): could not find vclass for uri '" + vclassURI + "'");
    }

    List<Individual> entsInVClass = daos.getIndividualDao().getIndividualsByVClass(vclass);
    if (entsInVClass == null) {
        throw new ServletException(
                "getEntitiesByVClass(): null List<Individual> retruned by getIndividualsByVClass() for "
                        + vclassURI);
    }
    int numberOfEntsInVClass = entsInVClass.size();

    List<Individual> entsToReturn = new ArrayList<Individual>(REPLY_SIZE);
    String requestHash = null;
    int count = 0;
    boolean more = false;
    /* we have a large number of items to send back so we need to stash the list in the session scope */
    if (entsInVClass.size() > REPLY_SIZE) {
        more = true;
        HttpSession session = vreq.getSession(true);
        requestHash = Integer.toString((vclassURI + System.currentTimeMillis()).hashCode());
        session.setAttribute(requestHash, entsInVClass);

        ListIterator<Individual> entsFromVclass = entsInVClass.listIterator();
        while (entsFromVclass.hasNext() && count < REPLY_SIZE) {
            entsToReturn.add(entsFromVclass.next());
            entsFromVclass.remove();
            count++;
        }
        if (log.isDebugEnabled()) {
            log.debug("getEntitiesByVClass(): Creating reply with continue token, found " + numberOfEntsInVClass
                    + " Individuals");
        }
    } else {
        if (log.isDebugEnabled())
            log.debug("getEntitiesByVClass(): sending " + numberOfEntsInVClass
                    + " Individuals without continue token");
        entsToReturn = entsInVClass;
        count = entsToReturn.size();
    }

    //put all the entities on the JSON array
    JSONArray ja = individualsToJson(entsToReturn);

    //put the responseGroup number on the end of the JSON array
    if (more) {
        try {
            JSONObject obj = new JSONObject();
            obj.put("resultGroup", "true");
            obj.put("size", count);
            obj.put("total", numberOfEntsInVClass);

            StringBuffer nextUrlStr = vreq.getRequestURL();
            nextUrlStr.append("?").append("getEntitiesByVClass").append("=1&").append("resultKey=")
                    .append(requestHash);
            obj.put("nextUrl", nextUrlStr.toString());

            ja.put(obj);
        } catch (JSONException je) {
            throw new ServletException("unable to create continuation as JSON: " + je.getMessage());
        }
    }

    log.debug("done with getEntitiesByVClass()");
    return ja;
}

From source file:dicky.controlleruser.AccountController.java

@RequestMapping(value = "myaccount", method = RequestMethod.POST)
public String myaccount(HttpServletRequest request, HttpSession session, ModelMap modelMap) {
    modelMap.put("title", "My Account");
    Account account = this.accountService.login(request.getParameter("username"),
            request.getParameter("password"));
    if (account != null) {
        session.setAttribute("username", request.getParameter("username"));
        modelMap.put("fullname", account.getFullname());
        return "account.welcome";
    } else {/*from  w w w . j a  v a2  s .c  o  m*/
        modelMap.put("error", "Account's Invalid!");
        return "account.myaccount";
    }

}