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:net.solarnetwork.node.setup.web.InstructorController.java

@RequestMapping(value = "/setControlParameter", method = RequestMethod.POST)
public String setControlParameter(SetControlParameterInstruction instruction, ModelMap model,
        HttpServletRequest request) {/*  w ww .java  2s .c om*/
    BasicInstruction instr = new BasicInstruction(InstructionHandler.TOPIC_SET_CONTROL_PARAMETER, new Date(),
            "LOCAL", "LOCAL", null);
    instr.addParameter(instruction.getControlId(), instruction.getParameterValue());
    InstructionStatus.InstructionState result = null;
    try {
        for (InstructionHandler handler : handlers) {
            if (handler.handlesTopic(instr.getTopic())) {
                result = handler.processInstruction(instr);
            }
            if (result != null) {
                break;
            }
        }
    } catch (RuntimeException e) {
        log.error("Exception setting control parameter {} to {}", instruction.getControlId(),
                instruction.getParameterValue(), e);
    }
    if (result == null) {
        // nobody handled it!
        result = InstructionStatus.InstructionState.Declined;
    }
    String keyPrefix = (result == InstructionStatus.InstructionState.Completed ? "status" : "error");
    HttpSession session = request.getSession();
    session.setAttribute(keyPrefix + "MessageKey", "controls.manage.SetControlParameter.result");
    session.setAttribute(keyPrefix + "MessageParam0", result);
    return "redirect:/controls/manage?id=" + instruction.getControlId();
}

From source file:com.dh.controller.user.UserController.java

@RequestMapping("/authenticate.do")
@ResponseBody/*from  w w  w.  ja  va 2  s.c  o  m*/
public Object authenticate(HttpServletRequest request, String account, String password) {

    LOG.info("authenticate,account?{},password?{}", account, password);
    if (StringUtils.isBlank(account) || StringUtils.isBlank(password)) {
        return JSON.toJSONString(new RespVO(-1, "????"));
    }

    User user = userService.authenticate(account, password);

    if (user == null) {
        return JSON.toJSONString(new RespVO(-2, "????"));
    }

    HttpSession session = request.getSession(true);
    session.setAttribute(SessionKey.DH_USER, user);

    return JSON.toJSONString(new RespVO(0, "?", user.getUserId()));
}

From source file:org.owasp.dependencytrack.controller.LoginController.java

/**
 * Writes (to a session attribute) whether the user was authenticated via LDAP or not.
 * @param request a HttpServletRequest object
 * @param isLdap a boolean indicating ldap authentication
 *//* w  w  w  .  j  a v  a  2  s  .  c  om*/
private void setLdapStatus(HttpServletRequest request, boolean isLdap) {
    final HttpSession session = request.getSession();
    if (session != null) {
        session.setAttribute("isLdap", isLdap);
    }
}

From source file:protocolo.controller.LoginController.java

@RequestMapping(value = "/logout")
public ModelAndView logout(HttpSession session) {
    ModelAndView modelAndView = new ModelAndView("login", "login", new Login());
    session.setAttribute("usuario_logado", null);
    SimpleDateFormat date = new SimpleDateFormat("dd/MM/yyyy");
    modelAndView.addObject("data", date.format(new Date()));
    return modelAndView;
}

From source file:cs425.yogastudio.controller.ProductController.java

@RequestMapping(value = "/product/{id}", method = RequestMethod.GET)
public String update(Model model, @PathVariable int id, HttpSession session) {
    session.setAttribute("product", productService.get(id));
    model.addAttribute("product", productService.get(id)); // 

    return "productUpdate";
}

From source file:cs425.yogastudio.controller.ProductController.java

@RequestMapping(value = "/productDetails/{id}", method = RequestMethod.GET)
public String goToProductDetail(@PathVariable int id, Model model, HttpSession session) {
    session.setAttribute("currentProduct", productService.get(id));
    model.addAttribute("currentProduct", session.getAttribute("currentProduct"));

    return "productDetail";
}

From source file:com.cme.hr.controller.FamilyMemberController.java

@RequestMapping(value = "/create", method = RequestMethod.POST)
public ModelAndView createNewFamilyMember(@ModelAttribute FamilyMember familyMember, BindingResult result,
        final RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    if (result.hasErrors()) {
        System.out.println("soy el error " + result.toString());
        ModelAndView mav = new ModelAndView("familyMember-new", "familyMember", familyMember);
        initSelect(mav);/*  ww w  .j  a  v a 2  s .  co  m*/
        return mav;
    }

    ModelAndView mav = new ModelAndView();
    String message = "New familyMember was successfully created.";
    redirectAttributes.addFlashAttribute("message", message);

    familyMemberService.create(familyMember);
    Integer p = familyMember.getIdPerson();
    HttpSession session = request.getSession(true);
    session.setAttribute("id_Person", p);

    mav.setViewName("redirect:/familyMember/list/{idPerson}.html");

    return mav;
}

From source file:cs425.yogastudio.controller.ProductController.java

@RequestMapping(value = "/products", method = RequestMethod.GET)
public String getAllProducts(HttpSession session) {

    session.setAttribute("products", productService.getAll());

    return "redirect:/toProductList";
}

From source file:cs425.yogastudio.controller.ProductController.java

@RequestMapping(value = "/searchProducts", method = RequestMethod.POST)
public String searchProductsByName(String searchText, HttpSession session) {

    session.setAttribute("products", productService.searchProductsByName(searchText));

    return "redirect:/toProductList";
}

From source file:com.hangum.tadpole.session.manager.SessionManager.java

/**
 *    . /*from  w w w. j ava 2  s.c om*/
 * @param key
 * @param obj
 */
public static void setUserInfo(String key, String obj) {

    HttpSession sStore = RWT.getRequest().getSession();
    Map<String, Object> mapUserInfoData = (Map<String, Object>) sStore.getAttribute(NAME.USER_INFO_DATA.name());
    UserInfoDataDAO userInfoDataDAO = (UserInfoDataDAO) mapUserInfoData.get(key);
    if (userInfoDataDAO == null) {
        userInfoDataDAO = new UserInfoDataDAO(SessionManager.getUserSeq(), key, obj);

        try {
            TadpoleSystem_UserInfoData.insertUserInfoData(userInfoDataDAO);
        } catch (Exception e) {
            logger.error("User data save exception [key]" + key + "[value]" + obj, e);
        }
    } else {
        userInfoDataDAO.setValue0(obj);
    }

    mapUserInfoData.put(key, userInfoDataDAO);
    sStore.setAttribute(NAME.USER_INFO_DATA.name(), mapUserInfoData);
}