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.test.springmvc.springmvcproject.IndexController.java

@RequestMapping(value = "register", method = RequestMethod.POST)
public String register(HttpSession session, ModelMap model, @Valid RegisterBean bean, BindingResult result) {

    if (!result.hasErrors()) {
        System.out.println("Pas d'erreurs !!");
        session.setAttribute("email_utilisateur", bean.getEmail());
        try {//from w ww .j  a  va2 s .c  om
            utilisateurService.create(bean);
        } catch (DuplicatedEntryException e) {
            result.addError(new FieldError("RegisterBean", "email", e.getMessage()));
            return "register";
        }
    } else {
        System.out.println("erreur presentes dans la validation : " + result.toString());
        return "register";
    }

    return "redirect:/index.do";
}

From source file:gov.nih.nci.security.upt.actions.CommonAssociationAction.java

public String loadAssociation(BaseAssociationForm baseAssociationForm) throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();
    session.setAttribute(DisplayConstants.CREATE_WORKFLOW, "0");

    if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) {
        if (logAssociation.isDebugEnabled())
            logAssociation.debug("||" + baseAssociationForm.getFormName()
                    + "|loadAssociation|Failure|No Session or User Object Forwarding to the Login Page||");
        return ForwardConstants.LOGIN_PAGE;
    }/*from www.jav  a2  s  . c om*/
    try {
        UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession())
                .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER);
        baseAssociationForm.setRequest(request);
        baseAssociationForm.buildAssociationObject(userProvisioningManager);
    } catch (CSException cse) {
        addActionError(org.apache.commons.lang.StringEscapeUtils.escapeHtml(cse.getMessage()));
        if (logAssociation.isDebugEnabled())
            logAssociation.debug(session.getId() + "|"
                    + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                    + baseAssociationForm.getFormName()
                    + "|loadAssociation|Failure|Error Loading Association for the "
                    + baseAssociationForm.getFormName() + "|" + cse.getMessage());
    }
    if (logAssociation.isDebugEnabled())
        logAssociation.debug(session.getId() + "|"
                + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                + baseAssociationForm.getFormName()
                + "|loadAssociation|Success|Success in loading association for "
                + baseAssociationForm.getFormName() + " object|");
    return ForwardConstants.LOAD_ASSOCIATION_SUCCESS;
}

From source file:com.estampate.corteI.servlet.guardarEstampa.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w w w. j a v  a2  s  .c  o  m*/
 *
 * @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();
    HttpSession objSesion = request.getSession(true);
    campos = new ArrayList<String>();
    //request.setAttribute("servlet", "ok");
    objSesion.setAttribute("servlet", "ok");
    //request.getRequestDispatcher("artista/administrarEstampa.jsp").forward(request, response);
    response.sendRedirect("artista/administrarEstampa.jsp");
    //    out.print(subioImagen);
    out.close();
}

From source file:com.job.portal.servlets.LoginRegisterServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    JSONObject obj = null, user = null;//from  ww w. j  a va  2 s  .c  om
    String email = null, pwd = null;
    boolean flag = false;
    UserDetails upb = new UserDetails();
    try {
        //            Map<String, String[]> m = request.getParameterMap();
        //            for (Map.Entry<String, String[]> e : m.entrySet()) {
        //                System.out.println(e.getKey() + "\t" + e.getValue()[0]);
        //            }
        if (request.getParameter("param") != null) {
            obj = new JSONObject();
            obj.put("status", false);
            String param = request.getParameter("param");
            if (request.getParameter("email") != null) {
                email = request.getParameter("email");
                if (ExpressionCheck.checkEmail(email)) {
                    if (request.getParameter("pwd") != null) {
                        pwd = request.getParameter("pwd");
                        if (!ExpressionCheck.checkPassword(pwd)) {
                            obj.put("msg", "Password should be atleast 3 characters long");
                        }
                    } else {
                        obj.put("msg", "Please provide a password");
                    }
                } else {
                    obj.put("msg", "Enter proper email");
                }
            } else {
                obj.put("msg", "Please provide an email");
            }
            if (!obj.has("msg")) {
                if (param.equalsIgnoreCase("register")) {
                    String name = null, phone = null, cPwd = null;
                    if (!new UserDetailsDAO().checkEmailExists(email)) {
                        if (request.getParameter("cPwd") != null) {
                            cPwd = request.getParameter("cPwd");
                            if (pwd.equalsIgnoreCase(cPwd)) {
                                if (request.getParameter("name") != null) {
                                    name = request.getParameter("name");
                                    if (ExpressionCheck.checkString(name)) {
                                        if (request.getParameter("phone") != null) {
                                            phone = request.getParameter("phone");
                                            if (!new UserDetailsDAO().checkPhoneExists(phone)) {
                                                if (ExpressionCheck.checkPhone(phone)) {
                                                    upb.setEmail(email);
                                                    upb.setName(name);
                                                    upb.setPhone(phone);
                                                    upb.setPwd(pwd);
                                                    UserDetails ud = new LoginRegisterManager()
                                                            .registerUser(upb);
                                                    obj.put("status", ud == null ? false : true);
                                                    if (flag) {
                                                        obj.put("msg", "Registered Successfully");
                                                        HttpSession sess = request.getSession(true);
                                                        sess.setAttribute("user", ud);
                                                    } else {
                                                        obj.put("msg", "Ooops!! Try again later");
                                                    }
                                                }
                                            } else {
                                                obj.put("msg", "Already registered with this number");
                                            }
                                        } else {
                                            obj.put("msg", "Enter a proper phone number");
                                        }
                                    }
                                } else {
                                    obj.put("msg", "Name can have only alphabets");
                                }
                            } else {
                                obj.put("msg", "Please provide your name");
                            }
                        } else {
                            obj.put("msg", "Password and confirm password do not match");
                        }
                    } else {
                        obj.put("msg", "Already registered with this email");
                    }
                } else if (param.equalsIgnoreCase("login")) {
                    user = new UserDetailsDAO().checkCredentials(email, pwd);
                    obj = new JSONObject();
                    obj.put("status", user == null ? false : true);
                    if (obj.getBoolean("status")) {
                        obj.put("msg", "Login Successful");
                        HttpSession sess = request.getSession(true);
                        sess.setAttribute("user", user);
                    } else {
                        obj.put("msg", "Email and password donot match");
                    }
                }
            }
        }
    } catch (Exception e) {
        LogOut.log.error("In " + new Object() {
        }.getClass().getEnclosingClass().getName() + "." + new Object() {
        }.getClass().getEnclosingMethod().getName() + " " + e);
    } finally {
        out.print(obj);
        out.close();
    }
}

From source file:gov.nih.nci.security.upt.actions.ApplicationAction.java

public String loadAssociation() throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();
    session.setAttribute(DisplayConstants.CREATE_WORKFLOW, "0");

    if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) {
        if (logAssociation.isDebugEnabled())
            logAssociation.debug("||" + applicationForm.getFormName()
                    + "|loadAssociation|Failure|No Session or User Object Forwarding to the Login Page||");
        return ForwardConstants.LOGIN_PAGE;
    }//from   www  .  j a  v  a 2s . c  o m
    try {
        UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession())
                .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER);
        applicationForm.setRequest(request);
        applicationForm.buildDisplayForm(userProvisioningManager);
        applicationForm.buildAssociationObject(userProvisioningManager);
    } catch (CSException cse) {
        addActionError(org.apache.commons.lang.StringEscapeUtils.escapeHtml(cse.getMessage()));
        if (logAssociation.isDebugEnabled())
            logAssociation.debug(session.getId() + "|"
                    + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                    + applicationForm.getFormName()
                    + "|loadAssociation|Failure|Error Loading Association for the "
                    + applicationForm.getFormName() + "|" + cse.getMessage());
    }
    if (logAssociation.isDebugEnabled())
        logAssociation.debug(session.getId() + "|"
                + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                + applicationForm.getFormName() + "|loadAssociation|Success|Success in loading association for "
                + applicationForm.getFormName() + " object|");
    return ForwardConstants.LOAD_ASSOCIATION_SUCCESS;
}

From source file:info.magnolia.cms.servlets.RequestInterceptor.java

/**
 * Request and Response here is same as receivced by the original page so it includes all post/get data. Sub action
 * could be called from here once this action finishes, it will continue loading the requested page.
 *///from   w  ww.j a  v a  2s.  c  om
public void doGet(HttpServletRequest request, HttpServletResponse response) {
    String action = request.getParameter(EntryServlet.INTERCEPT);
    String repository = request.getParameter(PARAM_REPOSITORY);
    if (repository == null) {
        repository = ContentRepository.WEBSITE;
    }
    HierarchyManager hm = MgnlContext.getHierarchyManager(repository);
    synchronized (ExclusiveWrite.getInstance()) {
        if (action.equals(ACTION_PREVIEW)) {
            // preview mode (button in main bar)
            String preview = request.getParameter(Resource.MGNL_PREVIEW_ATTRIBUTE);
            if (preview != null) {

                // @todo IMPORTANT remove use of http session
                HttpSession httpsession = request.getSession(true);
                if (BooleanUtils.toBoolean(preview)) {
                    httpsession.setAttribute(Resource.MGNL_PREVIEW_ATTRIBUTE, Boolean.TRUE);
                } else {
                    httpsession.removeAttribute(Resource.MGNL_PREVIEW_ATTRIBUTE);
                }
            }
        } else if (action.equals(ACTION_NODE_DELETE)) {
            // delete paragraph
            try {
                String path = request.getParameter(PARAM_PATH);
                // deactivate
                updatePageMetaData(request, hm);
                hm.delete(path);
                hm.save();
            } catch (RepositoryException e) {
                log.error("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
            }
        } else if (action.equals(ACTION_NODE_SORT)) {
            // sort paragrpahs
            try {
                String pathSelected = request.getParameter(PARAM_PATH_SELECTED);
                String pathSortAbove = request.getParameter(PARAM_PATH_SORT_ABOVE);
                String pathParent = StringUtils.substringBeforeLast(pathSelected, "/"); //$NON-NLS-1$
                String srcName = StringUtils.substringAfterLast(pathSelected, "/");
                String destName = StringUtils.substringAfterLast(pathSortAbove, "/");
                if (StringUtils.equalsIgnoreCase(destName, "mgnlNew")) {
                    destName = null;
                }
                hm.getContent(pathParent).orderBefore(srcName, destName);
                hm.save();
            } catch (RepositoryException e) {
                if (log.isDebugEnabled())
                    log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
            }
        }
    }
}

From source file:org.openmrs.module.web.controller.ModulePropertiesFormController.java

/**
 * The onSubmit function receives the form/command object that was modified by the input form
 * and saves it to the db/*from  ww  w  .  jav a  2s  . c o  m*/
 *
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(HttpServletRequest,
 *      HttpServletResponse, Object,
 *      BindException)
 */
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {

    if (!Context.hasPrivilege(PrivilegeConstants.MANAGE_MODULES)) {
        throw new APIAuthenticationException("Privilege required: " + PrivilegeConstants.MANAGE_MODULES);
    }

    HttpSession httpSession = request.getSession();
    String view = getFormView();
    String success = "";
    String error = "";

    view = getSuccessView();

    if (!"".equals(success)) {
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success);
    }

    if (!"".equals(error)) {
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error);
    }

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

From source file:miage.ecom.web.controller.CartController.java

@RequestMapping(value = "/cart")
public String index(Model model, HttpSession session) {

    CartBean cart;//from   w ww .j  av  a  2s.com
    if (session.getAttribute("cart") == null) {
        cart = new CartBean();
    } else {
        cart = (CartBean) session.getAttribute("cart");
        session.setAttribute("cart", cart);
    }

    List<Purchase> cartContents = ecomBeanFrontLocal.getCartContents(cart);
    model.addAttribute("cartTotalValue", ecomBeanFrontLocal.getTotalValue(cart));
    model.addAttribute("nbProducts", ecomBeanFrontLocal.getCartContents(cart).size());
    model.addAttribute("products", cartContents);
    return "cart";
}

From source file:jp.co.opentone.bsol.linkbinder.view.filter.LoginFilter.java

private void setDirectLogin(HttpServletRequest request, boolean timeout) {
    // ?ID?//from  w  w w.j av  a2 s . c o m
    RedirectScreenId screenId = RedirectScreenId.getPairedIdOf(request.getServletPath());
    switch (screenId) {
    case CORRESPON:
        String id = request.getParameter(RedirectProcessParameterKey.ID);
        String projectId = request.getParameter(RedirectProcessParameterKey.PROJECT_ID);

        // ???????????????
        // ???????????
        if (timeout && (StringUtils.isEmpty(id) || StringUtils.isEmpty(projectId))) {
            return;
        }

        ArgumentValidator.validateNotNull(id, RedirectProcessParameterKey.ID);
        ArgumentValidator.validateNotNull(projectId, RedirectProcessParameterKey.PROJECT_ID);

        // ??????????????true?
        HttpSession session = request.getSession(true);
        session.setAttribute(Constants.KEY_REDIRECT_SCREEN_ID, screenId);
        session.setAttribute(RedirectProcessParameterKey.ID, id);
        session.setAttribute(RedirectProcessParameterKey.PROJECT_ID, projectId);
        break;
    default:
        throw new ApplicationFatalRuntimeException("invalid screen id");
    }
}