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:com.leapfrog.springFramework.Controller.UserDashBoardController.java

@RequestMapping(value = "/user", method = RequestMethod.GET)
public ModelAndView userDashboard(HttpServletRequest request) {
    ModelAndView mv = new ModelAndView();
    HttpSession session = request.getSession(false);
    User user = (User) session.getAttribute("USER");

    if (session.getAttribute("USER") == null) {
        mv.setViewName("userLogin");

    } else {/* ww  w.  j a  v  a 2  s . c  o m*/
        List<faculties> facList = daoFac.getALL();
        List<Programme> progList = daoProg.getALL();
        List<Course> courseList = daoCourse.getALL();
        List<Question> questionList = daoQuestion.getByUserId(user.getUserId());

        List<EBooks> bookList = bookDao.getByUserId(user.getUserId());
        List<ModalPapers> modalList = modalDao.getByUserId(user.getUserId());

        mv.addObject("facList", facList);
        mv.addObject("progList", progList);
        mv.addObject("courseList", courseList);
        mv.addObject("bookList", bookList);
        mv.addObject("modalList", modalList);
        mv.addObject("questionList", questionList);
        mv.setViewName("everyOne/UserDashBoard");
    }
    return mv;
}

From source file:com.xhm.longxin.qth.web.user.common.QthUserSessionValve.java

public void invoke(PipelineContext pipelineContext) throws Exception {
    TurbineRunData rundata = getTurbineRunData(request);
    HttpSession session = rundata.getRequest().getSession();
    QthUser user = null;//from   w w  w  . ja  va2s .  c  om

    try {
        user = (QthUser) session.getAttribute(UserConstant.QTH_USER_SESSION_KEY);
    } catch (Exception e) {
        log.warn("Failed to read qthUser from session: " + UserConstant.QTH_USER_SESSION_KEY, e);
    }

    if (user == null) {
        // 
        user = new QthUser();
        session.setAttribute(UserConstant.QTH_USER_SESSION_KEY, user);
    }

    // userrundata      PetstoreUser.setCurrentUser(user);
    user.upgrade();
    pipelineContext.invokeNext(); // valves
}

From source file:gsn.http.OutputStructureHandler.java

public boolean isValid(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String vsName = request.getParameter("name");

    //Added by Behnaz
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("user");

    if (vsName == null || vsName.trim().length() == 0) {
        response.sendError(WebConstants.MISSING_VSNAME_ERROR, "The virtual sensor name is missing");
        return false;
    }/*w w  w  .j  a va  2  s .  c o  m*/
    VSensorConfig sensorConfig = Mappings.getVSensorConfig(vsName);
    if (sensorConfig == null) {
        response.sendError(WebConstants.ERROR_INVALID_VSNAME, "The specified virtual sensor doesn't exist.");
        return false;
    }

    //Added by Behnaz.
    if (user != null) // meaning, that a login session is active, otherwise we couldn't get there
        if (Main.getContainerConfig().isAcEnabled() == true) {
            if (user.hasReadAccessRight(vsName) == false && user.isAdmin() == false) // ACCESS_DENIED
            {
                response.sendError(WebConstants.ACCESS_DENIED,
                        "Access denied to the specified virtual sensor .");
                return false;
            }
        }

    return true;
}

From source file:org.shredzone.cilla.web.page.ResourceLockManagerImpl.java

@Override
@SuppressWarnings("unchecked")
public boolean isUnlocked(HttpSession session, BaseModel entity) {
    Map<String, Set<Long>> unlockMap = (Map<String, Set<Long>>) session.getAttribute(STORE_UNLOCK_ATTRIBUTE);

    if (unlockMap != null) {
        Set<Long> unlockSet = unlockMap.get(getEntityName(entity));
        if (unlockSet != null) {
            return unlockSet.contains(entity.getId());
        }/* w  w w  . j  a v a  2 s.  c  om*/
    }

    return false;
}

From source file:com.viseur.control.AddComment.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request// www .  ja v a  2  s.  co m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    int item = Integer.valueOf(request.getParameter("itemtype"));
    int itemId = Integer.valueOf(request.getParameter("itemid"));
    String cmntText = request.getParameter("comment");

    HttpSession session = request.getSession();
    User usr = (User) session.getAttribute("user");
    String addedTime = DateCUtil.getSimpleDateTime();

    int success = 0;
    ConceptItem rateItm = null;
    ItemComment c = new ItemComment(usr.regId, cmntText, addedTime);
    int cmtId = c.createComment();

    if (cmtId > 0) {
        if (item == 1) {
            rateItm = new Project(itemId);
        } else if (item == 2) {
            rateItm = new Idea(itemId);
        }
        if (rateItm != null) {
            if (rateItm.addComment(cmtId)) {
                success = 1;
            }
        }
    }

    JSONObject json = new JSONObject();
    json.put("success", success);
    if (success == 1) {
        json.put("userName", usr.username);
        json.put("time", DateCUtil.convertToDateTime(addedTime));
        json.put("id", cmtId);
    } else {
        json.put("error", "Please try again");
    }

    try (PrintWriter out = response.getWriter()) {
        out.print(json.toString());
        out.flush();
    }

}

From source file:cs544.letmegiveexam.aspect.EmailAspect.java

@After("execution (* cs544.letmegiveexam.controller.UserExamController.sumbitExam(..))&& args(questionSet,result,session,Id,setId) ")
public void logUserExam(JoinPoint point, QuestionSet questionSet, BindingResult result, HttpSession session,
        long Id, long setId) {
    UserExam userExam = userExamService.get(Id);
    User user = (User) session.getAttribute("user");
    String subject = "Here is the result for your Exam give on LetMeGiveExam";
    subject = subject + "\n Subject: "
            + userExam.getQuestionSet().getQuestionslist().get(0).getSubject().getName();
    subject = subject + "\n Score: " + userExam.getScore();
    subject = subject + "\n Duration: " + userExam.getDuration();
    emailManager.sendEmail(mailSender, "LetMeGiveExam Score Card", subject, user.getEmail());
}

From source file:com.starr.smartbuilds.controller.AddController.java

@RequestMapping(method = RequestMethod.POST)
public String saveBuild(@ModelAttribute("build") Build build, BindingResult result, Model model,
        HttpServletRequest req, HttpServletResponse resp) throws IOException {
    HttpSession session = req.getSession();
    User user = (User) session.getAttribute("user");
    build.setUser(user);/*  w  w w  .ja  v a  2  s.c o  m*/
    build.setSeason("Season V");
    build.setPatch("5.16.1");
    build.setUser(user);

    Long championId = Long.parseLong(req.getParameter("champion"));
    build.setChampion(championDAO.getChampion(championId));

    Long buildId = buildDAO.addBuild(build);
    Build build_new = buildDAO.getBuild(buildId);

    System.out.println("------BUILD--------");
    System.out.println("Name:" + build.getName());
    System.out.println("Map:" + build.getMap());
    System.out.println("Role:" + build.getRole());
    System.out.println("Lane:" + build.getLane());
    System.out.println("Type:" + build.getType());
    System.out.println("BLOCKS" + build.getBlocks());

    resp.sendRedirect("./build?id=" + build_new.getId());

    List<Category> categories = categoryDAO.listCategories();
    model.addAttribute("categories", categories);
    List<Tag> tags = tagDAO.listTags();
    model.addAttribute("tags", tags);
    List<Champion> champions = championDAO.listChampions();
    model.addAttribute("champions", champions);
    model.addAttribute("build", new Build());
    return "add_build";
}

From source file:eventmanager.controller.RelatoriosController.java

@RequestMapping(value = "/User/relatorio")
public ModelAndView relatorio(HttpSession session) {
    ModelAndView modelAndView = new ModelAndView("relatorio");
    User user = (User) session.getAttribute("usuario_logado");
    ArrayList aux = new ArrayList();
    List<Event> eventoList = user.getMeusEventos();
    for (Event evento : eventoList) {
        aux.add(evento.getInscritos().size());
    }//from   www.j ava 2 s .com
    int qtd = 0;
    for (Object aux1 : aux) {
        qtd += (int) aux1;
    }
    List inscricaoList = user.getMinhasInscricoes();
    System.out.println(inscricaoList.size());
    modelAndView.addObject("quantidadeEventos", eventoList.size());
    modelAndView.addObject("quantidadeInscritos", inscricaoList.size());
    modelAndView.addObject("quantidadeInscritosMeusEventos", qtd);
    modelAndView.addObject("usuario", user.getNome());
    modelAndView.addObject("nomeEvento", new Busca());

    return RenderView.getInstance().renderRelatorioViewUser(user, modelAndView);
}

From source file:com.bxf.hradmin.security.AuthenticationSuccessHandler.java

/**
 * session?url??/*from   w w  w  . j  a v a 2 s . c o  m*/
 * @param request request
 * @throws IOException IOException
 */
protected void doRedirect(HttpServletRequest request, HttpServletResponse response) throws IOException {
    HttpSession session = request.getSession();
    SavedRequest savedRequest = (SavedRequest) session.getAttribute("SPRING_SECURITY_SAVED_REQUEST");
    if (savedRequest != null) {
        redirectStrategy.sendRedirect(request, response, savedRequest.getRedirectUrl());
    } else {
        redirectStrategy.sendRedirect(request, response, defaultTargetUrl);
    }
}