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:csns.web.controller.SectionController.java

private String list(String type, Quarter quarter, ModelMap models, HttpSession session) {
    if (quarter != null)
        session.setAttribute("quarter", quarter);
    else if (session.getAttribute("quarter") != null)
        quarter = (Quarter) session.getAttribute("quarter");
    else/*from  www  .  j a  v  a2s.c  o  m*/
        quarter = new Quarter();

    User user = SecurityUtils.getUser();
    List<Quarter> quarters = null;
    List<Section> sections = null;
    String view = "error";
    switch (type) {
    case "taught":
        quarters = quarterDao.getQuartersByInstructor(user);
        sections = sectionDao.getSectionsByInstructor(user, quarter);
        view = "section/taught";
        break;

    case "taken":
        quarters = quarterDao.getQuartersByStudent(user);
        sections = sectionDao.getSectionsByStudent(user, quarter);
        view = "section/taken";
        break;

    case "evaluated":
        quarters = quarterDao.getQuartersByEvaluator(user);
        sections = sectionDao.getSectionsByEvaluator(user, quarter);
        view = "section/evaluated";
        break;

    default:
        logger.warn("Invalid section type: " + type);
    }

    Quarter currentQuarter = new Quarter();
    if (!quarters.contains(currentQuarter))
        quarters.add(0, currentQuarter);
    Quarter nextQuarter = currentQuarter.next();
    if (!quarters.contains(nextQuarter))
        quarters.add(0, nextQuarter);

    models.put("user", user);
    models.put("quarter", quarter);
    models.put("quarters", quarters);
    models.put("sections", sections);
    return view;
}

From source file:com.jmu.service.Patchca.PatchcaService.java

/**
 *    ???/*  w  w  w  .j a va  2s. c o  m*/
 * @param width
 * @param height
 * @param os
 * @param session ?session
 * @throws IOException
 */
public void getPatchca(int width, int height, OutputStream os, HttpSession session) throws IOException {
    resetcs(width, height);
    String token = EncoderHelper.getChallangeAndWriteImage(cs, "png", os);
    session.setAttribute("patchca", token);
}

From source file:org.musicrecital.webapp.filter.LocaleFilter.java

/**
 * This method looks for a "locale" request parameter. If it finds one, it sets it as the preferred locale
 * and also configures it to work with JSTL.
 * //from   w  ww.java2  s .c  o m
 * @param request the current request
 * @param response the current response
 * @param chain the chain
 * @throws IOException when something goes wrong
 * @throws ServletException when a communication failure happens
 */
@SuppressWarnings("unchecked")
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    String locale = request.getParameter("locale");
    Locale preferredLocale = null;

    if (locale != null) {
        int indexOfUnderscore = locale.indexOf('_');
        if (indexOfUnderscore != -1) {
            String language = locale.substring(0, indexOfUnderscore);
            String country = locale.substring(indexOfUnderscore + 1);
            preferredLocale = new Locale(language, country);
        } else {
            preferredLocale = new Locale(locale);
        }
    }

    HttpSession session = request.getSession(false);

    if (session != null) {
        if (preferredLocale == null) {
            preferredLocale = (Locale) session.getAttribute(Constants.PREFERRED_LOCALE_KEY);
        } else {
            session.setAttribute(Constants.PREFERRED_LOCALE_KEY, preferredLocale);
            Config.set(session, Config.FMT_LOCALE, preferredLocale);
        }

        if (preferredLocale != null && !(request instanceof LocaleRequestWrapper)) {
            request = new LocaleRequestWrapper(request, preferredLocale);
            LocaleContextHolder.setLocale(preferredLocale);
        }
    }

    chain.doFilter(request, response);

    // Reset thread-bound LocaleContext.
    LocaleContextHolder.setLocaleContext(null);
}

From source file:ke.co.tawi.babblesms.server.servlet.sms.send.SendSMS.java

/**
 * Method to handle form processing/*from  w  w  w.j  ava2s . co m*/
 * 
 * @param request
 * @param response
 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 * 
 * @throws IOException
 */
@SuppressWarnings("unchecked")
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {

    // Respond as soon as possible to the client request
    HttpSession session = request.getSession(true);
    session.setAttribute(SessionConstants.SENT_SUCCESS, "success");
    response.sendRedirect("sendsms.jsp");

    // Get the relevant account      
    Account account = new Account();

    String username = request.getParameter("username");

    Element element;
    if ((element = accountsCache.get(username)) != null) {
        account = (Account) element.getObjectValue();
    }

    TawiGateway smsGateway = gatewayDAO.get(account);

    // Retrieve the web parameters
    String[] groupselected = request.getParameterValues("groupselected");
    String[] phones = request.getParameterValues("phones");
    String source = request.getParameter("source");
    String message = request.getParameter("message");

    // Deal with the case where one or more Groups has been selected
    // Get phones of all the Contacts in the Group(s)
    SetUniqueList phoneList = SetUniqueList.decorate(new LinkedList<Phone>()); // Does not allow duplicates 

    Group group;
    List<Contact> contactList;
    List<OutgoingGrouplog> outgoingGroupList = new LinkedList<>();

    if (groupselected != null) {
        OutgoingGrouplog groupLog;

        for (String groupUuid : groupselected) {
            group = new Group();
            group.setUuid(groupUuid);
            contactList = ctgrpDAO.getContacts(group);

            for (Contact contact : contactList) {
                phoneList.addAll(phoneDAO.getPhones(contact));
            }

            // Save an outgoing log for the group 
            groupLog = new OutgoingGrouplog();
            groupLog.setMessagestatusUuid(MsgStatus.SENT);
            groupLog.setSender(account.getUuid());
            groupLog.setDestination(group.getUuid());
            groupLog.setMessage(message);
            outgoingGroupList.add(groupLog);

        } // end 'for(String groupUuid : groupselected)'
    } // end 'if(groupselected != null)'

    // This is the case where individual Contacts may have been selected      
    if (phones == null) {
        phones = new String[0];
    }
    phones = StringUtil.removeDuplicates(phones);

    for (String phone : phones) {
        phoneList.add(phoneDAO.getPhone(phone));
    }

    // Determine whether a shortcode or mask is the source
    SMSSource smsSource;
    Shortcode shortcode = shortcodeDAO.get(source);
    Mask mask = null;
    if (shortcode == null) {
        mask = maskDAO.get(source);
        smsSource = mask;

    } else {
        smsSource = shortcode;
    }

    // Set the network in the groups (if any) and save the log
    for (OutgoingGrouplog log : outgoingGroupList) {
        log.setNetworkUuid(smsSource.getNetworkuuid());
        log.setOrigin(smsSource.getUuid());
        groupLogDAO.put(log);
    }

    // Filter the phones to the Network of the source (mask or short code)
    List<Phone> validPhoneList = new LinkedList<>();
    validPhoneList.addAll(
            CollectionUtils.select(phoneList, new PhonesByNetworkPredicate(smsSource.getNetworkuuid())));

    // Break down the phone list to go out to manageable sizes, each sublist
    // being sent to the SMS Gateway in one URL POST
    List<List<Phone>> phonePartition = ListPartitioner.partition(validPhoneList, 10);

    // Send the lists one by one
    PostSMS postThread;

    for (List<Phone> list : phonePartition) {
        postThread = new PostSMS(smsGateway, list, smsSource, message, account, true);

        postThread.start();
    }

    // Deduct credit
    smsBalanceDAO.deductBalance(account, smsSource, validPhoneList.size());
}

From source file:csns.web.controller.WikiController.java

@RequestMapping(value = "/wiki/password", method = RequestMethod.POST)
public String password(@RequestParam String path, @RequestParam String password, HttpSession session) {
    if (pageDao.getPage(path).getPassword().equals(password))
        session.setAttribute(path, "password verifeid");

    return "redirect:" + path;
}

From source file:edu.hm.muse.controller.Logincontroller.java

private ModelAndView returnToLogin(HttpSession session) {
    //Ohhhhh not correct try again
    ModelAndView mv = new ModelAndView("login");
    mv.addObject("msg", "Sorry try again");
    session.setAttribute("login", false);
    return mv;/*from  ww  w.j  av a2  s .com*/
}

From source file:com.br.uepb.controller.LoginController.java

@RequestMapping(value = "/index/login.html", method = RequestMethod.POST)
public ModelAndView loginPost(@ModelAttribute("loginDomain") LoginDomain login, HttpSession session,
        Model model) {/*from  w w  w .  j a  v a 2 s  . c o m*/
    LoginBusiness loginBusiness = new LoginBusiness();
    ModelAndView modelAndView = new ModelAndView();
    if (login != null) {
        if (loginBusiness.loginValido(login.getLogin(), login.getSenha())) {
            session.setAttribute("login", login.getLogin());
            SessaoBusiness sessao = new SessaoBusiness();

            // Recupera o login da base de dados para obter o id do login
            // Esse passo  necessrio pois cada atualizao na base de dados s  feita a partir do id
            LoginDomain loginAtualizado = loginBusiness.obtemLogin(login.getLogin(), login.getSenha());

            sessao.setLoginDomain(loginAtualizado);
            GerenciarSessaoBusiness.addSessaoBusiness(loginAtualizado, sessao);
            modelAndView.setViewName("redirect:/home/home.html");
        } else {
            modelAndView.setViewName("index/login");
            String mensagem = "Login ou senha est incorreto";
            modelAndView.addObject("mensagem", mensagem);
            modelAndView.addObject("status", "1");
        }
    }
    return modelAndView;
}

From source file:com.thumbsup.coolname.AccountController.java

@RequestMapping(value = "/account/login", method = RequestMethod.POST)
public ModelAndView postLogin(@RequestParam(value = "usr", required = true, defaultValue = "") String username,
        @RequestParam(value = "psw", required = true, defaultValue = "") String password,
        HttpServletRequest request) {//from   w w w  .  j a va2s  .c o  m
    String page = "";
    if (username.equals("") || password.equals("")) {
        page = "login";
        request.setAttribute("l", false);
    } else {
        UserManager manager = new UserManager();
        User u = manager.login(username, password);
        password = null;
        if (u == null) {
            page = "login";
            request.setAttribute("l", false);
        } else {
            page = "redirect:/";
            HttpSession session = request.getSession();
            session.setAttribute("auth", u.getUserId());
        }
    }

    return new ModelAndView(page);
}

From source file:com.sun.socialsite.web.filters.SessionFilter.java

/**
 *
 *///from  w w w  .j  av  a  2 s . co m
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest httpReq = (HttpServletRequest) req;
    String remoteUser = httpReq.getRemoteUser();

    if (remoteUser != null) {

        HttpSession httpSession = httpReq.getSession();
        if (httpSession.getAttribute(REMOTE_USER) == null) {
            log.debug(
                    String.format("Setting REMOTE_USER=%s on Session[id=%s]", remoteUser, httpSession.getId()));
            httpSession.setAttribute(REMOTE_USER, remoteUser);
        }

        assert (httpSession.equals(SessionListener.getSession(httpSession.getId())));

    }

    chain.doFilter(req, resp);

}

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

private void storeWCtx(String wctx, HttpServletRequest request) {
    HttpSession httpSession = request.getSession();
    httpSession.setAttribute(WCTX_SESSION_ATTRIBUTE, wctx);
}