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.ss.Controller.T4uGoToScheduleServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w  ww. j  av  a 2  s.  co  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 {
    List<Integer> allScheduleIds = T4uScheduleDAO.getAllScheduleIds();
    List<T4uSchedule> allSchedules = new ArrayList<T4uSchedule>();
    for (int scheduleId : allScheduleIds)
        allSchedules.add(T4uScheduleDAO.getScheduleById(scheduleId));
    Map<Integer, T4uHouse> allHouses = T4uHouseDAO.getAllHouses();
    Map<Integer, T4uMovie> allMovies = T4uMovieDAO.getAllMovies();
    for (Map.Entry<Integer, T4uMovie> entry : allMovies.entrySet()) {
        Integer key = entry.getKey();
        T4uMovie value = entry.getValue();
        value.setAllVersions(T4uVersionDAO.getAllVersions(value));
    }
    HttpSession session = request.getSession(true);
    session.setAttribute(T4uConstants.T4uAllSchedules, allSchedules);
    session.setAttribute(T4uConstants.T4uAllHouses, allHouses);
    session.setAttribute(T4uConstants.T4uAllMovies, allMovies);

    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/schedules.jsp");
    dispatcher.forward(request, response);
}

From source file:Binder.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();
    HttpSession session = req.getSession(true);
    SessionObject o = new SessionObject(getServletContext());
    session.setAttribute("Binder.object", o);
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Session Binder</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("Object bound to session " + session.getId());

    out.println("</body>");
    out.println("</html>");
    out.flush();/*from w  ww .j  av a2s.  com*/
}

From source file:irille.pub.verify.RandomImageServlet.java

/**
 * ????HTTP?/*from w ww  .  j  a v  a 2s  .  c om*/
 */
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    boolean gif_enabled = support(req, "image/gif") || !support(req, "image/png");
    HttpSession ssn = req.getSession(true);
    String randomString = random();
    ssn.setAttribute(RANDOM_LOGIN_KEY, randomString);
    res.setContentType(gif_enabled ? "image/gif" : "image/png");
    res.setHeader("Pragma", "No-cache");
    res.setHeader("Cache-Control", "no-cache");
    res.setDateHeader("Expires", 0);
    render(randomString, gif_enabled, res.getOutputStream());
}

From source file:com.eventestimator.mvc.ContactCollectionController.java

@RequestMapping(value = "/tab.j", method = RequestMethod.GET)
protected String handleRequestInternal(Model model, HttpServletRequest request) throws Exception {

    String accessToken = request.getParameter("access_token");
    String userName = request.getParameter("userName");
    String eventUrl = WS_URL_PREFIX + userName + "/events?access_token=" + accessToken;
    String contactUrl = WS_URL_PREFIX + userName + "/contacts?access_token=" + accessToken;

    HttpSession session = request.getSession();
    session.setAttribute("accessToken", accessToken);
    session.setAttribute("userName", userName);
    return "contact_list";
}

From source file:org.iwethey.forums.web.user.NewUserController.java

/**
 * Process a submitted form by creating the user and placing the user name in the session.
 * <p>//from  w w  w .  j  a  v a 2 s  .  c om
 * @param request The servlet request object.
 * @param response The servlet response object.
 * @param command The form backing store object (a User object).
 * @param errors The Spring errors object.
 * @return The model and view.
 */
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) {
    User user = (User) command;

    int id = mUserManager.createNewUser(user);

    HttpSession sess = request.getSession();
    sess.setAttribute(USER_ID_ATTRIBUTE, new Integer(id));

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

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

@RequestMapping(value = "/courses/{id}", method = RequestMethod.GET)
public String getCourse(@PathVariable int id, Model model, HttpSession session) {
    session.setAttribute("currentCourse", courseService.get(id));
    model.addAttribute("currentCourse", session.getAttribute("currentCourse"));

    List<Section> sections = ((Course) session.getAttribute("currentCourse")).getSections();
    model.addAttribute("sections", sections);

    return "courseDetail";
}

From source file:com.tsg.techsupportmvc.UserController.java

@RequestMapping(value = { "/logout" }, method = RequestMethod.POST)
public String logUserOut(HttpServletRequest request, RedirectAttributes redirectAttributes,
        HttpSession session) {

    userIsLoggedIn = false;//w  w w  .java  2s .co  m
    error = "";
    session.setAttribute("userIsLoggedIn", userIsLoggedIn);
    session.setAttribute("user", "");
    session.setAttribute("userRealName", "");
    session.setAttribute("userSiteRole", "");
    session.setAttribute("loginErrorMessage", error);
    return "redirect:home";

}

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

@RequestMapping(value = "/course/{id}", method = RequestMethod.GET)
public String update(Course course, Model model, @PathVariable int id, HttpSession session) {

    session.setAttribute("course", courseService.get(id));
    model.addAttribute("course", courseService.get(id));
    //model.addAttribute("allcourses", courseService.getAll());
    //session.setAttribute("allcourses", courseService.get(id));

    return "courseUpdate";
}

From source file:org.owasp.webgoat.controller.About.java

/**
 * <p>welcome.</p>/*  ww  w. j a va 2 s.com*/
 *
 * @param request a {@link javax.servlet.http.HttpServletRequest} object.
 * @param error a {@link java.lang.String} object.
 * @param logout a {@link java.lang.String} object.
 * @return a {@link org.springframework.web.servlet.ModelAndView} object.
 */
@RequestMapping(value = "about.mvc", method = RequestMethod.GET)
public ModelAndView welcome(HttpServletRequest request,
        @RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "logout", required = false) String logout) {

    // set the welcome attribute
    // this is so the attack servlet does not also 
    // send them to the welcome page
    HttpSession session = request.getSession();
    if (session.getAttribute(WELCOMED) == null) {
        session.setAttribute(WELCOMED, "true");
    }

    //go ahead and send them to webgoat (skip the welcome page)
    ModelAndView model = new ModelAndView();
    //model.setViewName("welcome");
    //model.setViewName("main_new");
    model.setViewName("about");
    return model;
}

From source file:org.owasp.webgoat.controller.Welcome.java

/**
 * <p>welcome.</p>//from www. j a  v  a2  s. c o m
 *
 * @param request a {@link javax.servlet.http.HttpServletRequest} object.
 * @param error a {@link java.lang.String} object.
 * @param logout a {@link java.lang.String} object.
 * @return a {@link org.springframework.web.servlet.ModelAndView} object.
 */
@RequestMapping(value = "welcome.mvc", method = RequestMethod.GET)
public ModelAndView welcome(HttpServletRequest request,
        @RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "logout", required = false) String logout) {

    // set the welcome attribute
    // this is so the attack servlet does not also 
    // send them to the welcome page
    HttpSession session = request.getSession();
    if (session.getAttribute(WELCOMED) == null) {
        session.setAttribute(WELCOMED, "true");
    }

    //go ahead and send them to webgoat (skip the welcome page)
    ModelAndView model = new ModelAndView();
    //model.setViewName("welcome");
    //model.setViewName("main_new");
    model.setViewName("forward:/attack?start=true");
    return model;
}