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:bc8.movies.controllers.LoginController.java

@RequestMapping(value = "/validateLogin", method = RequestMethod.POST)
public ModelAndView validateLogin(User user, HttpSession session) {
    ModelAndView mv = new ModelAndView("home");

    User currUser = userService.getUser(user);
    if (currUser != null) {
        session.setAttribute("user", currUser);
        mv.setViewName("redirect:/listFavorites");
    }/*w w w  . j a v a2s .  c om*/

    return mv;
}

From source file:com.tsg.cms.HomeController.java

@RequestMapping(value = "/admin", method = RequestMethod.GET)
public String showAdminPage(HttpServletRequest req, Model model, HttpSession session) {

    String htmlOutput = req.getParameter("htmlOutput");
    model.addAttribute("htmlOutput", htmlOutput);
    session.setAttribute("page", "admin");
    session.setAttribute("js_page", "admin.js");

    return "home";
}

From source file:com.virtusa.akura.user.controller.UserRoleDetailsLoadController.java

/**
 * Get the user role id and set it to admin details to view the search staff details.
 * /*w ww.j  av a2s.  com*/
 * @param request - HttpServletRequest
 * @param session - HttpSession
 * @param model - ModelMap
 * @return view of student details
 */
@RequestMapping(value = LOAD_USER_ROLE_DETAILS)
public String loadData(HttpServletRequest request, HttpSession session, ModelMap model) {

    if (request.getParameter(USER_ROLE_ID) != null) {
        int userRoleId = Integer.parseInt(request.getParameter(USER_ROLE_ID));
        session.setAttribute(USER_ROLE_ID, userRoleId);
    }

    return REDIRECT_VIEW_USER_ROLE_DETAILS;
}

From source file:controle.LoginControler.java

@RequestMapping(value = "/efetuarLogin.htm", method = RequestMethod.POST)
public String efetuarLogin(@ModelAttribute("usuario") Usuario usuario, UsuarioDao dao,
        HttpServletRequest request, HttpSession session) {

    for (Usuario u : dao.consultarTodosUsuarios()) {
        if (usuario.getLogin().equals(u.getLogin()) && usuario.getSenha().equals(u.getSenha())) {
            session.setAttribute("token", "aprovado");
            return "index";
        }//from   w  w w  . java2s.  c om

    }
    request.setAttribute("mensagem", "Usuario Invalido");
    return "login";
}

From source file:de.betterform.agent.web.servlet.XFormsInspectorServlet.java

private void sendError(HttpServletRequest request, HttpServletResponse response, HttpSession session,
        Exception e, String message) throws ServletException, IOException {
    session.setAttribute("betterform.exception", e);
    session.setAttribute("betterform.exception.message", message);
    session.setAttribute("betterform.referer", request.getRequestURL());
    String path = null;//from  w  w w .j a va  2s . c o  m
    try {
        path = "/" + Config.getInstance().getProperty(WebFactory.ERROPAGE_PROPERTY);
    } catch (XFormsConfigException ce) {
        ce.printStackTrace();
    }
    getServletContext().getRequestDispatcher(path).forward(request, response);
}

From source file:org.openmrs.module.kenyametadatatools.web.controller.mflsync.SynchronizeController.java

/**
 * Handles requests to start a synchronization task
 * @param options the synchronization options
 * @param session the http session/*w ww  .  jav  a2s.c  o  m*/
 * @return the view name
 */
@RequestMapping(value = "/module/kenyametadatatools/mflsync/synchronize", method = RequestMethod.POST)
public String submit(@ModelAttribute("options") MflSyncOptions options, ModelMap model, HttpSession session) {

    try {
        if (!Context.hasPrivilege(PrivilegeConstants.MANAGE_LOCATIONS)) {
            session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Insufficient privileges");
        } else {
            URL url = new URL(options.getSpreadsheetUrl());
            LocationAttributeType attrType = options.getAttributeType();

            BaseMflSyncTask task = new MflSyncFromRemoteSpreadsheetTask(attrType, url);

            if (TaskEngine.start(task)) {
                return "redirect:synchronize.form";
            } else {
                session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Task already running");
            }
        }
    } catch (MalformedURLException ex) {
        session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Invalid spreadsheet URL");
        log.error(ex);
    }

    return showForm(options, model);
}

From source file:org.openmrs.module.populatingactivelists.web.controller.ProblemsMigrationController.java

@RequestMapping(value = "/module/obsconverter/problemsmigration", method = RequestMethod.POST)
public void afterPageSubmission(@RequestParam("problemAddedConcept") Integer problemAddedConceptId,
        @RequestParam("problemRemovedConcept") Integer problemResolvedConceptId, HttpSession httpSession) {

    int count = super.afterPageSubmission(problemAddedConceptId, problemResolvedConceptId, this);
    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,
            "All active observations are migrated to active problems list successfully. total migrated observations: "
                    + count);//  w  ww  .  jav  a 2s . c  o  m
}

From source file:edu.harvard.i2b2.oauth2.AuthenticationService.java

public void authenticateSession(String authHeaderContent, HttpSession session) {
    AccessToken tok = getHttpAccessTokenString(authHeaderContent);
    logger.trace("inserting accessToken into Session:" + tok + "\nsession:" + session);
    session.setAttribute("accessToken", tok);
}

From source file:CounterServer.java

public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpSession session = req.getSession(true);
    int count = 1;
    Integer i = (Integer) session.getAttribute(COUNTER_KEY);
    if (i != null) {
        count = i.intValue() + 5;//from w  ww. j  av  a 2s  .  c  o m
    }
    session.setAttribute(COUNTER_KEY, new Integer(count));
    DataInputStream in = new DataInputStream(req.getInputStream());
    resp.setContentType("application/octet-stream");
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(byteOut);
    out.writeInt(count);
    out.flush();
    byte[] buf = byteOut.toByteArray();
    resp.setContentLength(buf.length);
    ServletOutputStream servletOut = resp.getOutputStream();
    servletOut.write(buf);
    servletOut.close();
}

From source file:net.cit.tetrad.resource.LoginResource.java

@RequestMapping("/login.do")
public ModelAndView login(HttpServletRequest request, CommonDto dto) throws Exception {
    log.debug("login start");

    ModelAndView mav = new ModelAndView();
    Query query = new Query();
    try {//from  w  w w  . j a  v  a2 s  . c  om
        int count = (int) monadService.getCount(query, User.class);
        if (count == 0) {
            insertSuperUser();
            mav.setViewName("login");
            mav.addObject("releaseVersion", PropertiesNames.RELEASEVERSIONINFO);
            mav.addObject("licensekey", Config.LICENSEKEY);
            mav.addObject("licensetype", Config.LICENSETYPE);
        } else {
            User user = doLogin(dto, mav);
            HttpSession session = request.getSession();
            session.setAttribute("loginUserCode", user.getIdx());
            session.setAttribute("loginAuth", user.getAuthority());
            session.setMaxInactiveInterval(1800);
        }
    } catch (Exception e) {
        dto.setMessage(" ?.");
    }
    mav.addObject("comm", dto);
    log.debug("login end");
    return mav;
}