Example usage for javax.servlet.http HttpSession getAttribute

List of usage examples for javax.servlet.http HttpSession getAttribute

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession getAttribute.

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the object bound with the specified name in this session, or null if no object is bound under the name.

Usage

From source file:cs544.letmegiveexam.controller.UserExamController.java

@RequestMapping(value = "/examHistory", method = RequestMethod.GET)
public String examHistory(Model model, HttpSession session) {
    User user = (User) session.getAttribute("user");

    List<UserExam> userExamList = userExamService.getUserExam(user.getId());
    //System.out.println("userExamList size:" + (userExamList != null ? userExamList.size() : "Null"));
    model.addAttribute("userExamList", userExamList);
    return "examHistory";
}

From source file:chiron.maxscore.servlet.SecurityServlet.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpSession session = ((HttpServletRequest) request).getSession();
    Object role = session.getAttribute("role");
    if (role == null) {
        ObjectMapper mapper = new ObjectMapper();
        Map<String, Object> map = new HashMap<>();
        map.put("success", false);
        map.put("msg", "");
        mapper.writeValue(response.getWriter(), map);
    }//w  w  w .j ava  2 s  .c o  m
    chain.doFilter(request, response);
}

From source file:com.naver.timetable.bo.LoginBO.java

public void logout(HttpServletRequest request) {
    HttpSession session = request.getSession();
    if (session.getAttribute("user") != null) {
        session.removeAttribute("user");
    }//from w w  w  . j  av  a  2s  .c  o m
}

From source file:springku.BelajarController.java

@RequestMapping("/keluar")
public String keluar(HttpServletRequest request) {
    HttpSession httpSession = request.getSession();
    if (httpSession.getAttribute("username") != null) {
        httpSession.invalidate();//from   w  w  w . j  a  va2s . c  o m
        ;
    }
    return "redirect:formlogin";
}

From source file:com.quangphuong.crawler.controller.HomeController.java

@RequestMapping(value = "/dashboard.htm", method = RequestMethod.GET)
public String dashboard(HttpServletRequest request, HttpServletResponse response, Model model,
        HttpSession session) throws Exception {
    User userInfo = (User) session.getAttribute("USER");
    if (userInfo != null) {
        model.addAttribute("xmlStr", userService.getUserList());
    }/*ww w . ja va2s  .c  om*/

    //        userService.getUserList();
    return "dashboard";
}

From source file:mx.com.quadrum.contratos.controller.crud.ContratoController.java

@ResponseBody
@RequestMapping(value = "agregarContrato", method = RequestMethod.POST)
public String agregarContrato(@Valid @ModelAttribute("contrato") Contrato contrato, BindingResult bindingResult,
        HttpSession session) {
    if (session.getAttribute("usuario") == null) {
        return SESION_CADUCA;
    }/*  w  ww.  jav  a2s .  co  m*/
    if (bindingResult.hasErrors()) {
        return ERROR_DATOS;
    }
    return contratoService.agregar(contrato);
}

From source file:mx.com.quadrum.contratos.controller.crud.ContratoController.java

@ResponseBody
@RequestMapping(value = "editarContrato", method = RequestMethod.POST)
public String editarContrato(@Valid @ModelAttribute("contrato") Contrato contrato, BindingResult bindingResult,
        HttpSession session) {
    if (session.getAttribute("usuario") == null) {
        return SESION_CADUCA;
    }/*from   ww w.ja va  2 s.co m*/
    if (bindingResult.hasErrors()) {
        return ERROR_DATOS;
    }
    return contratoService.editar(contrato);
}

From source file:mx.com.quadrum.contratos.controller.crud.PermisoController.java

@RequestMapping(value = "permiso", method = RequestMethod.GET)
public String permiso(Model model, HttpSession session) {
    Usuario usuario = (Usuario) session.getAttribute("usuario");
    List<Permiso> permisos = (List<Permiso>) session.getAttribute(PERMISOS);

    if (usuario == null && permisos == null) {
        return "templates/index";
    }/* ww w.j  a  v a  2 s.c  om*/
    model.addAttribute("permisos", permisos);
    return "crud/permiso";
}

From source file:eventmanager.controller.ConfigController.java

@RequestMapping(value = "/User/config")
public ModelAndView config(HttpSession session) {
    ModelAndView modelAndView = new ModelAndView("index");
    User user = (User) session.getAttribute("usuario_logado");
    modelAndView.addObject("usuario", user.getNome());
    modelAndView.addObject("link", true);
    modelAndView.addObject("nomeEvento", new Busca());
    return RenderView.getInstance().renderConfigViewUser(user, modelAndView);
}

From source file:org.owasp.webgoat.service.PluginReloadService.java

/**
 * Reload all the plugins//  w w  w .  j a  v  a 2 s  . c  om
 *
 * @param session a {@link HttpSession} object.
 */
@RequestMapping(value = "/reloadplugins.mvc")
public @ResponseBody ResponseEntity<String> reloadPlugins(HttpSession session) {
    WebSession webSession = (WebSession) session.getAttribute(WebSession.SESSION);
    logger.debug("Loading plugins into cache");
    String pluginPath = session.getServletContext().getRealPath("plugin_lessons");
    String targetPath = session.getServletContext().getRealPath("plugin_extracted");
    new PluginsLoader(Paths.get(pluginPath), Paths.get(targetPath)).copyJars();

    webSession.getCourse().loadLessonFromPlugin(session.getServletContext());
    return new ResponseEntity("Plugins reload refresh the WebGoat page!", HttpStatus.OK);
}