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:be.fedict.eid.dss.protocol.simple.SimpleDSSProtocolService.java

private void storeRelayState(String relayState, HttpSession httpSession) {
    httpSession.setAttribute(RELAY_STATE_PARAMETER, relayState);
}

From source file:br.mdarte.exemplo.academico.cd.crud.ManageCurso.java

private void saveMaxResultsWarning(HttpServletRequest request) {
    final HttpSession session = request.getSession();

    ActionMessages messages = (ActionMessages) session.getAttribute(org.apache.struts.Globals.MESSAGE_KEY);
    if (messages == null) {
        messages = new ActionMessages();
        session.setAttribute(org.apache.struts.Globals.MESSAGE_KEY, messages);
    }//  w  w  w.  j  a va  2s.c  o  m
    messages.add("org.andromda.bpm4struts.warningmessages",
            new ActionMessage("maximum.results.fetched.warning", "250"));
}

From source file:Controller.ControllerCustomers.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w  w  w . j  a  v  a 2s .c  om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {
        String action = request.getParameter("action");
        if (action.equals("Login")) {
            String user = request.getParameter("txtId");
            String pass = request.getParameter("txtpass");
            Customers ct = new Customers();
            String anh = ct.anh(user);
            boolean check = ct.checkLogin(user, pass);
            String url = "error.jsp";
            if (check) {
                if (ct.role(user)) {
                    RequestDispatcher rd = request.getRequestDispatcher("Admin.jsp");
                    rd.forward(request, response);
                } else {

                    url = "index_Cus_2.jsp";
                    HttpSession session = request.getSession(true);
                    session.setAttribute("User", user);
                    session.setAttribute("Image", anh);
                    //                   <%

                    CartDao listsp = new CartDao();
                    List<Cart> list = CartDao.layDanhSachCart(user);
                    session.setAttribute("list", list);
                    //      %>

                }

            }
            RequestDispatcher rd = request.getRequestDispatcher(url);
            rd.forward(request, response);

        } else if (action.equals("FIND")) {
            String username = request.getParameter("txtusername");
            CustomerDAO cusdao = new CustomerDAO();
            List<Customer> list = new ArrayList<Customer>();
            list = cusdao.layDanhSachKhachHang(username);
            request.setAttribute("listKH", list);
            RequestDispatcher rd = request.getRequestDispatcher("CustomerDao.jsp");
            rd.forward(request, response);

        } else if (action.equals("DELETE")) {
            String username = request.getParameter("txtusername");
            boolean delete = CustomerDAO.XoaKhachHang(username);
            if (delete) {
                RequestDispatcher rd = request.getRequestDispatcher("CustomerDao.jsp");
                rd.forward(request, response);

            }

        } else if (action.equals("Edit")) {
            String username = request.getParameter("txtusername");
            String password = request.getParameter("txtpassword");
            String hoten = request.getParameter("txthoten");
            String gioitinh = request.getParameter("txtgioitinh");
            String email = request.getParameter("txtemail");
            String role = request.getParameter("txtrole");
            String anh = request.getParameter("txtanh");
            Customer cus = new Customer(username, password, hoten, gioitinh, email, role, anh);
            request.setAttribute("Cus", cus);
            RequestDispatcher rd = request.getRequestDispatcher("editCustomer.jsp");
            rd.forward(request, response);

        }
    } catch (Exception e) {
        e.printStackTrace();

    }

}

From source file:com.archsystemsinc.ipms.sec.webapp.controller.RequirementController.java

@RequestMapping(value = "/edit-requirement/{id}", method = RequestMethod.GET)
public String editRequirement(@PathVariable("id") final Long id, final Model model) {
    final Requirement requirement = service.findOne(id);
    model.addAttribute("requirement", requirement);
    model.addAttribute("referenceData", referenceData());

    final HttpSession session = getSession();
    session.setAttribute("requirement", requirement);
    return "requirementsedit";
}

From source file:com.ext.portal.events.HomeLandingPageAction.java

public void run(HttpServletRequest request, HttpServletResponse response) {
    _log.error("Starting HomeLandingPageAction");
    java.lang.Long userId = (java.lang.Long) request.getAttribute(WebKeys.USER_ID);
    if (request.getSession() != null) {
        userId = (java.lang.Long) request.getSession().getAttribute(WebKeys.USER_ID);
    }/*from   w  w  w.jav  a  2 s . co m*/
    String path = null;
    if (userId != null) {
        _log.error("user id:  " + userId.toString());
        List<UserGroup> userGroups = null;
        // 10106 appears to be the default company id
        long company = 0;
        try {
            userGroups = UserGroupLocalServiceUtil.getUserUserGroups(userId.longValue());
            _log.error("user group count:  " + userGroups.size());
        } catch (Exception e) {
            // error getting user groups
            _log.error("*** USER GROUPS ERROR *** " + e.getMessage());
        }
        try {
            _log.error("user id:  " + userId.longValue());
            User user = UserLocalServiceUtil.getUserById(userId.longValue());
            if (user != null) {
                _log.error("user -- " + user.getFullName());
                company = user.getCompanyId();
                _log.error("company-- " + company);
            } else {
                _log.error("user is null");
            }
        } catch (PortalException e) {
            _log.error("*** USER PORTAL EXCEPTION *** " + e.getMessage());
            e.printStackTrace();
        } catch (SystemException e) {
            _log.error("*** USER SYSTEM EXCEPTION *** " + e.getMessage());
            e.printStackTrace();
        } catch (Exception e) {
            _log.error("*** USER EXCEPTION *** " + e.getMessage());
            e.printStackTrace();
        }
        if (userGroups.size() > 0) {
            Group group = null;
            List<Group> groups = null;
            try {
                groups = GroupLocalServiceUtil.search(PortalUtil.getCompanyId(request), null, null, null,
                        QueryUtil.ALL_POS, QueryUtil.ALL_POS);
            } catch (SystemException e) {
                _log.error("*** GROUPS SYSTEM EXCEPTION *** " + e.getMessage());
                e.printStackTrace();
            } catch (Exception e) {
                _log.error("*** GROUPS EXCEPTION *** " + e.getMessage());
                e.printStackTrace();
            }
            if (groups.size() > 0) {
                _log.error("groups count-- " + groups.size());
                Iterator<UserGroup> itu = userGroups.iterator();
                _log.error("User Group iterator instantiated");
                while (itu.hasNext()) {
                    _log.error("Inside User Group Loop");
                    UserGroup tempUG = itu.next();
                    _log.error("user group-- " + tempUG.getName() + "/" + tempUG.getUserGroupId());
                    Iterator<Group> itg = groups.iterator();
                    while (itg.hasNext()) {
                        _log.error("Inside Group Loop");
                        try {
                            Group tempG = itg.next();
                            _log.error("group-- " + tempG.getGroupId() + "/" + tempG.getName());
                            if (UserGroupLocalServiceUtil.hasGroupUserGroup(tempG.getGroupId(),
                                    tempUG.getUserGroupId())) {
                                _log.error("Group has user group!");
                                int pageCount = tempG.getPrivateLayoutsPageCount()
                                        + tempG.getPublicLayoutsPageCount();
                                _log.error("page count-- " + pageCount);
                                if (pageCount != 0) {
                                    group = tempG;
                                    _log.error(
                                            "We have a group-- " + group.getName() + "/" + group.getGroupId());
                                    break;
                                }
                            }
                        } catch (SystemException e) {
                            _log.error("*** FIND GROUP SYSTEM EXCEPTION *** " + e.getMessage());
                            e.printStackTrace();
                        } catch (Exception e) {
                            _log.error("*** FIND GROUP EXCEPTION *** " + e.getMessage());
                            e.printStackTrace();
                        }
                    }
                    if (group != null) {
                        break;
                    } else {
                        _log.error("*** NO COMMUNITIES FOUND FOR USER GROUP *** ");
                    }
                }
            } else {
                _log.error("*** NO COMMUNITIES FOUND IN SYSTEM *** ");
            }
            try {
                // if we have user groups, try to find all the communities
                // that user is a part of
                // based on the user group list
                if (group != null) {
                    _log.error("group-- " + group.getGroupId() + "/" + group.getName());
                    // if we have communities, pick the first from the list
                    // and get the url
                    path = ((GroupImpl) group).getFriendlyURL();
                    _log.error("path-- " + path);
                } else {
                    // no communities = can't do much
                    _log.error("*** NO COMMUNITIES ***");
                }
            } catch (Exception e) {
                // error getting communities
                _log.error("*** COMMUNITIES ERROR *** " + e.getMessage());
            }
        } else {
            // no user group = can't do much
            _log.error("*** NO USER GROUPS ***");
        }
    } else {
        // no user = can't do much
        _log.error("*** NULL USER_ID ***");
    }
    if (_log.isInfoEnabled()) {
        _log.info("HomeLandingPageAction=" + (path != null ? path : "<null>"));
    }
    if (Validator.isNotNull(path)) {
        // if we don't have a null path, go there
        //LastPath lastPath = new LastPath("/web", path,
        LastPath lastPath = new LastPath("/group", path, new HashMap<String, String[]>());
        HttpSession session = request.getSession();
        session.setAttribute(WebKeys.LAST_PATH, lastPath);
    }
}

From source file:com.skilrock.lms.web.userMgmt.common.ProcessSearchOrgForAgentAction.java

public String search() throws LMSException {
    HttpSession session = getRequest().getSession(true);
    session.setAttribute("ORG_SEARCH_RESULTS", null);
    session.setAttribute("ORG_SEARCH_RESULTS1", null);
    logger.debug("hello i sm in search User");
    logger.debug("org Name:" + orgName);
    logger.debug("org Type:" + orgType);
    logger.debug("org Status:" + orgStatus);

    logger.debug("hello i sm in search User");
    logger.debug("org Name:" + orgName);
    logger.debug("org Type:" + orgType);
    logger.debug("org Status:" + orgStatus);

    UserInfoBean userInfo = null;//from  ww w.ja  v  a 2  s  .com
    // logger.debug(userInfo.getgetRoleName());
    userInfo = (UserInfoBean) session.getAttribute("USER_INFO");
    int intagentId = userInfo.getUserOrgId();
    Integer ii = new Integer(intagentId);
    String agentId = ii.toString();
    logger.debug("User Id: " + userInfo.getUserId());
    logger.debug(">>>>>>>>" + userInfo.getUserId());
    Map<String, String> searchMap = new HashMap<String, String>();
    searchMap.put("ORG_NAME", orgName);
    searchMap.put("ORG_TYPE", orgType);
    searchMap.put("ORG_STATUS", orgStatus);
    searchMap.put("AGENT_ID", agentId);
    if (orgStatus.equals("1")) {

        searchMap.put("ORG_STATUS", null);
    } else {
        searchMap.put("ORG_STATUS", orgStatus);
    }
    if (orgType.equals("1")) {

        searchMap.put("ORG_TYPE", null);
    } else {
        searchMap.put("ORG_TYPE", orgType);
    }

    SearchOrgHelper searchOrgHelper = new SearchOrgHelper();
    List searchResults = searchOrgHelper.searchOrgForRetailer(searchMap);
    logger.debug("Search Results : " + searchResults);
    logger.debug(searchResults);
    if (searchResults != null && searchResults.size() > 0) {
        logger.debug("Yes:---Search result Processed");
        logger.debug("Yes:---Search result Processed");
        session.setAttribute("ORG_SEARCH_RESULTS1", searchResults);
        logger.debug("List " + searchResults);
        session.setAttribute("startValueOrgAgSearch", new Integer(0));
        setOrgsearchResultsAvailable("Yes");
        searchAjax();
    } else {
        setOrgsearchResultsAvailable("No");
        logger.debug("No:---Search result Processed");
        logger.debug("No:---Search result Processed");
    }

    return SUCCESS;
}

From source file:com.skilrock.lms.web.userMgmt.common.ProcessSearchAgentAction.java

/**
 * This method is used to search Company(Org)
 * /* w w w . j  av  a  2s .co m*/
 * @BO
 * @return SUCCESS
 * @throws LMSException
 */

public String search() throws LMSException {
    HttpSession session = getRequest().getSession();
    session.setAttribute("ORG_SEARCH_RESULTS", null);
    session.setAttribute("ORG_SEARCH_RESULTS1", null);
    logger.debug("search Organization @BO");
    logger.debug("org Name:" + orgName);
    logger.debug("org Type:" + orgType);
    logger.debug("org Status:" + orgStatus);
    logger.debug("hello i am in search Organization @BO");
    logger.debug("org Name:" + orgName);
    logger.debug("org Type:" + orgType);
    logger.debug("org Status:" + orgStatus);

    Map<String, String> searchMap = new HashMap<String, String>();
    searchMap.put("ORG_NAME", orgName);
    searchMap.put("ORG_TYPE", orgType);
    searchMap.put("ORG_STATUS", orgStatus);
    if (orgStatus.equals("1")) {

        searchMap.put("ORG_STATUS", null);
    } else {
        searchMap.put("ORG_STATUS", orgStatus);
    }
    if (orgType.equals("1")) {

        searchMap.put("ORG_TYPE", null);
    } else {
        searchMap.put("ORG_TYPE", orgType);
    }

    SearchAgentHelper searchOrgHelper = new SearchAgentHelper();
    List<OrganizationBean> searchResults = searchOrgHelper.searchOrg(searchMap);
    logger.debug("Org Search Results " + searchResults);
    logger.debug("Org Search Results " + searchResults);
    if (searchResults != null && searchResults.size() > 0) {
        logger.debug("Search result Processed");
        logger.debug("Yes:---Search result Processed");

        session.setAttribute("ORG_SEARCH_RESULTS1", searchResults);
        session.setAttribute("startValueOrgSearch", new Integer(0));
        setOrgsearchResultsAvailable("Yes");
    } else {
        setOrgsearchResultsAvailable("No");
        logger.debug("No:---Search result Processed");
        logger.debug("No:---Search result Processed");
    }

    searchAjax();

    return SUCCESS;
}

From source file:com.alibaba.sample.petstore.web.store.module.action.CartAction.java

public void doAddItem(HttpSession session, @Param("itemId") String itemId, Context context) throws Exception {
    Cart cart = (Cart) session.getAttribute(PETSTORE_CART_KEY);

    if (cart == null) {
        cart = new Cart();
    }//  w  w  w  .ja  va 2s  .  co m

    cart.addCartItem(itemId);

    session.setAttribute(PETSTORE_CART_KEY, cart);

    context.put("itemAdded", Boolean.TRUE);
}

From source file:mx.com.quadrum.contratos.controller.HomeController.java

@RequestMapping(value = "inicio")
public String inicio(String rfc, String password, Model model, HttpSession session) {
    if (usuarioService.estaRegistrado(rfc, password)) {
        Usuario usuario = usuarioService.buscarPorCorreo(rfc);
        List<Permiso> permisos = permisoService.buscarPorUsuario(usuario.getId());

        session.setAttribute(USUARIO, usuario);
        session.setAttribute(PERMISOS, permisos);
        session.setAttribute(CLIENTE, null);

        if (usuario.getPrimeraSesion()) {
            return ("usuario/cambiarPass");
        }//from   ww  w.  ja va  2 s  .  c o  m
        model.addAttribute("permisos", permisos);
        if (usuario.getEsAdmin()) {
            model.addAttribute("esAdmin", "esAdmin");
        }
        model.addAttribute("nombre",
                usuario.getNombres() + " " + usuario.getPaterno() + " " + usuario.getMaterno());
        return ("templates/inicio");
    }
    model.addAttribute("estaRegistrado", false);
    return ("templates/index");
}

From source file:org.openmrs.module.idcards.web.controller.TemplateFormController.java

/**
 * Handles the user's submission of the form.
 *//*from ww w.  j a  v  a  2s  .  c  o  m*/
@RequestMapping(method = RequestMethod.POST, params = "action=save")
public String onSave(@ModelAttribute("template") IdcardsTemplate template, HttpSession httpSession) {

    if (Context.isAuthenticated()) {
        IdcardsService service = (IdcardsService) Context.getService(IdcardsService.class);
        service.saveIdcardsTemplate(template);
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "idcards.template.saved");
    }

    return "redirect:/module/idcards/templates.list";
}