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:controller.ContaController.java

@RequestMapping("login")
public String login2(HttpServletRequest req, HttpSession cookie) {
    ContaDao dao = new ContaDao();
    Conta user;/*from ww w  .j  a v  a2s  .co m*/
    user = dao.logar(req.getParameter("email"), req.getParameter("senha"));
    if (user != null) {
        cookie.setAttribute("usuarioLogado", user);
        return "redirect:telainicial";
    }
    return "telaprincipal";
}

From source file:be.fedict.eid.idp.sp.protocol.saml2.AuthenticationRequestServlet.java

private void setRequestId(String requestId, HttpSession session) {
    session.setAttribute(REQUEST_ID_SESSION_ATTRIBUTE, requestId);
}

From source file:be.fedict.eid.idp.sp.protocol.saml2.AuthenticationRequestServlet.java

private void setRequestIssuer(String requestIssuer, HttpSession session) {
    session.setAttribute(REQUEST_ISSUER_SESSION_ATTRIBUTE, requestIssuer);
}

From source file:be.fedict.eid.idp.sp.protocol.saml2.AuthenticationRequestServlet.java

private void setRecipient(String recipient, HttpSession session) {
    session.setAttribute(RECIPIENT_SESSION_ATTRIBUTE, recipient);
}

From source file:be.fedict.eid.idp.sp.protocol.saml2.AuthenticationRequestServlet.java

private void setRelayState(String relayState, HttpSession session) {
    session.setAttribute(RELAY_STATE_SESSION_ATTRIBUTE, relayState);
}

From source file:org.eg.sc.web.ShopJsonAction.java

public String clear() {
    try {/*from  w  w w  .j a  va  2  s  .  c o m*/
        HttpSession session = ServletActionContext.getRequest().getSession();
        OrderCar car = new OrderCar();
        session.setAttribute("Car", car);
        datas.put("flag", 1);
    } catch (Exception e) {
        e.printStackTrace();
        datas.put("flag", 0);
    }

    return SUCCESS;
}

From source file:com.third.rent.user.controller.LoginController.java

@RequestMapping(value = "/user/login.do", method = RequestMethod.POST)
public String login_post(@RequestParam String userId, @RequestParam String userPwd,
        @RequestParam(required = false) String chkSaveId, HttpServletRequest request,
        HttpServletResponse response, Model model) {
    // 1//w ww.j  av  a2 s . c  o m
    logger.info("? , ? userId={} userPwd={}", userId, userPwd);
    logger.info("? chkSaveId={}", chkSaveId);

    // 2
    int result = userService.loginCheck(userId, userPwd);
    logger.info("?  , ? result={}", result);

    String msg = "", url = "/user/login.do";
    if (result == userService.LOGIN_OK) {
        UserVO vo = userService.selectByUserid(userId);

        msg = vo.getUserName() + " ? ?.";
        url = "/user/index.do";

        // ? 
        HttpSession session = request.getSession();
        session.setAttribute("userId", userId);
        session.setAttribute("userName", vo.getUserName());
        session.setAttribute("userLicense", vo.getUserLicense());

        // ? 
        Cookie ck = new Cookie("ck_userId", userId);
        ck.setPath("/");
        // ?  ? 
        if (chkSaveId != null) {
            ck.setMaxAge(1000 * 24 * 60 * 60); // 1000?
            response.addCookie(ck);
        } else {
            ck.setMaxAge(0); //  
            response.addCookie(ck);
        }

    } else if (result == userService.ID_NONE) {
        msg = " ?  .";
    } else if (result == userService.PWD_DISAGREE) {
        msg = " ? ";
    } else {
        msg = "? ? ";
    }
    // 3
    model.addAttribute("msg", msg);
    model.addAttribute("url", url);

    return "common/message";
}

From source file:co.estampas.servlets.guardarEstampa.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//w  w w . ja  va2s  .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");
    try {
        HttpSession objSesion = request.getSession(true);
        objSesion.setAttribute("estampas", null);
        /* TODO output your page here. You may use following sample code. */
        List<EstampaCamiseta> estampas = new ArrayList<>();
        estampas = estampaCamisetaFacade.estampaByArtista(artistaFacade.find(this.idArtistax));
        objSesion.setAttribute("estampas", estampas);

        //request.setAttribute("servlet", "ok");
        objSesion.setAttribute("servlet", "ok");
        //request.getRequestDispatcher("artista/administrarEstampa.jsp").forward(request, response);
        response.sendRedirect("artista/administrarEstampa.jsp");
        //    out.print(subioImagen);
    } catch (Exception ex) {

    }

}

From source file:org.openmrs.module.appointmentscheduling.web.controller.AppointmentBlockCalendarController.java

@RequestMapping(method = RequestMethod.POST)
public String loadForm(HttpServletRequest request, ModelMap model,
        @RequestParam(value = "action", required = false) String action,
        @RequestParam(value = "locationId", required = false) Location location,
        @RequestParam(value = "chosenType", required = false) Integer appointmentTypeId,
        @RequestParam(value = "chosenProvider", required = false) Integer providerId,
        @RequestParam(value = "fromDate", required = false) Long fromDate,
        @RequestParam(value = "toDate", required = false) Long toDate,
        @RequestParam(value = "appointmentBlockId", required = false) Integer appointmentBlockId) {
    if (Context.isAuthenticated()) {
        //Updating session variables
        Calendar cal = OpenmrsUtil.getDateTimeFormat(Context.getLocale()).getCalendar();
        cal.setTimeInMillis(fromDate);/*from  w  w w.  j a v a2 s.  co  m*/
        Date fromDateAsDate = cal.getTime();
        cal.setTimeInMillis(toDate);
        Date toDateAsDate = cal.getTime();
        HttpSession httpSession = request.getSession();
        httpSession.setAttribute("chosenLocation", location);
        httpSession.setAttribute("lastLocale", Context.getLocale());
        httpSession.setAttribute("chosenProvider", providerId);
        httpSession.setAttribute("chosenType", appointmentTypeId);
        //If the user wants to add new appointment block (clicked on a day)
        if (action != null && action.equals("addNewAppointmentBlock")) {
            String getRequest = "";
            //Fill the request from the user with selected date and forward it to appointmentBlockForm
            getRequest += "fromDate=" + Context.getDateTimeFormat().format(fromDateAsDate);
            if (toDate != null && !toDate.equals(fromDate)) { //If the fromDate is not the same as toDate (not a day click on month view)
                getRequest += "&toDate=" + Context.getDateTimeFormat().format(toDateAsDate);
            }
            getRequest += "&redirectedFrom=appointmentBlockCalendar.list";
            return "redirect:appointmentBlockForm.form?" + getRequest;
        }
        //If the user wants to change the view to table view
        else if (action != null && action.equals("changeToTableView")) {
            return "redirect:appointmentBlockList.list";
        }
        //If the user wants to edit an existing appointment block (clicked on an event)
        else if (action != null && action.equals("editAppointmentBlock")) {
            return "redirect:appointmentBlockForm.form?appointmentBlockId=" + appointmentBlockId
                    + "&redirectedFrom=appointmentBlockCalendar.list";
        }
    }

    return null;
}