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:edu.uiowa.icts.authentication.AuthHandle.java

/** {@inheritDoc} */
@Override//from  ww  w  .ja  v  a 2 s  .  c o  m
public void onAuthenticationSuccess(HttpServletRequest req, HttpServletResponse res, Authentication auth)
        throws IOException, ServletException {

    log.debug("successfully authenticated " + String.valueOf(auth.getPrincipal()));

    if (req.getSession().getAttribute("SPRING_SECURITY_LAST_EXCEPTION") != null) {
        req.getSession().removeAttribute("SPRING_SECURITY_LAST_EXCEPTION");
    }

    for (GrantedAuthority ga : auth.getAuthorities()) {
        log.debug(ga.getAuthority());
    }

    HttpSession session = req.getSession();
    String username = req.getParameter("j_username");
    session.setAttribute("username", username);

    AuditLogger.info(session.getId(), username, "logged in from", req.getRemoteHost());

    target.onAuthenticationSuccess(req, res, auth);

}

From source file:it.jugpadova.controllers.EventEditController.java

private void clearSpeakerSession(HttpSession session) {
    session.setAttribute(SESSION_SPEAKER, null);
    session.setAttribute(ORIGINAL_SESSION_SPEAKER, null);
}

From source file:org.openmrs.web.controller.concept.ConceptStopWordFormControllerTest.java

/**
 * @see {@link ConceptStopWordFormController#handleSubmission(HttpSession, ConceptStopWordFormBackingObject, org.springframework.validation.BindingResult)
 *///from ww  w.j av a  2  s  .  c  o m
@Test
@Verifies(value = "should return error message for an empty ConceptStopWord", method = "handleSubmission(HttpSession, ConceptStopWordFormBackingObject, BindingResult)")
public void handleSubmission_shouldReturnErrorMessageForAnEmptyConceptStopWord() throws Exception {
    ConceptStopWordFormController controller = (ConceptStopWordFormController) applicationContext
            .getBean("conceptStopWordFormController");

    HttpSession mockSession = new MockHttpSession();

    ConceptStopWord conceptStopWord = new ConceptStopWord("", Locale.CANADA);

    mockSession.setAttribute("value", conceptStopWord.getValue());
    BindException errors = new BindException(conceptStopWord, "value");

    controller.handleSubmission(mockSession, conceptStopWord, errors);
    ObjectError objectError = (ObjectError) errors.getAllErrors().get(0);

    Assert.assertTrue(errors.hasErrors());
    Assert.assertEquals(1, errors.getErrorCount());
    Assert.assertEquals("ConceptStopWord.error.value.empty", objectError.getCode());
}

From source file:cn.cug.laboratory.web.BaseController.java

/**
 * ? HttpSession /* w  w w.jav  a 2s.  c o m*/
 * @param name
 * @param value
 */
public void setHttpSessionAttribute(String name, Object value) {
    HttpSession session = this.getHttpSession();
    session.setAttribute(name, value);
}

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

@RequestMapping(value = "/pageTinyMCE", method = RequestMethod.GET)
public String showEditor(Map<String, Object> model, HttpSession session) {

    session.setAttribute("page", "pageTinyMCE");

    session.setAttribute("js_page", "pageTinyMCE.js");
    return "home";
}

From source file:com.dh.controller.user.UserController.java

@RequestMapping("/registOther.do")
@ResponseBody/*w w  w.  ja va2 s .c  om*/
public Object registOther(HttpServletRequest request, String open_id, int platform) {

    LOG.info("registOther:,open_id?{},platform?{}", open_id, platform);
    User user = userService.getByOpenId(open_id);

    if (user == null) {
        String userId = UUIDUtils.getNumUUID(8);
        user = new User();
        user.setPlatform(0);
        user.setCreateTime(new Date());
        user.setUserId(userId);
        boolean result = userService.regist(user);
        if (!result) {
            LOG.error("registOther:,open_id?{},platform?{},user_id?{}",
                    open_id, platform, userId);
            return JSON.toJSONString(new RespVO(-2, ""));
        }

        LOG.info("registOther:?,open_id?{},platform?{},user_id?{}", open_id,
                platform, userId);
    }

    HttpSession session = request.getSession(true);
    session.setAttribute(SessionKey.DH_USER, user);
    return JSON.toJSONString(new RespVO(0, "?", user));

}

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

private void setContext(String context, HttpSession session) {
    session.setAttribute(CONTEXT_SESSION_ATTRIBUTE, context);
}

From source file:com.anritsu.mcreleaseportal.utils.FileUpload.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//w ww.j  a v a 2s. com
 *
 * @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 {

    HttpSession session = request.getSession();
    session.setAttribute("mcPackage", null);
    PrintWriter pw = response.getWriter();
    response.setContentType("text/plain");
    ServletFileUpload upload = new ServletFileUpload();
    try {
        FileItemIterator iter = upload.getItemIterator(request);

        while (iter.hasNext()) {
            FileItemStream item = iter.next();
            InputStream stream = item.openStream();

            // Save input stream file for later use
            File dir = new File(Configuration.getInstance().getSavePath());
            if (!dir.exists() && !dir.isDirectory()) {
                dir.mkdir();
                LOGGER.log(Level.INFO, "Changes.xml archive directory was created at " + dir.getAbsolutePath());
            }
            String fileName = request.getSession().getId() + "_" + System.currentTimeMillis();
            File file = new File(dir, fileName);
            file.createNewFile();
            Path path = file.toPath();
            Files.copy(stream, path, StandardCopyOption.REPLACE_EXISTING);
            LOGGER.log(Level.INFO, "changes.xml saved on disk as: " + file.getAbsolutePath());

            // Save filename to session for next calls
            session.setAttribute("xmlFileLocation", file.getAbsolutePath());
            LOGGER.log(Level.INFO, "changes.xml saved on session as: fileName:" + file.getAbsolutePath());

            // Cleanup
            stream.close();

        }

    } catch (FileUploadException | IOException | RuntimeException e) {
        pw.println(
                "An error occurred when trying to process uploaded file! \n Please check the file consistency and try to re-submit. \n If the error persist pleace contact system administrator!");
    }
}

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

@RequestMapping(value = "/pagelink/{titleNumber}", method = RequestMethod.GET)
public String getLinkedPage(@PathVariable("titleNumber") String titleNumber, Map<String, Object> model,
        HttpSession session) {

    session.setAttribute("page", "singleStaticPage");

    session.setAttribute("js_page", "singleStaticPage.js");
    int id = staticPageDao.getStaticPageByTitleNumber(titleNumber).getPageId();
    model.put("id", id);
    return "home";
}

From source file:com.pkrete.locationservice.admin.controller.mvc.EditUserController.java

@RequestMapping(method = RequestMethod.POST)
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute("userInfo") UserInfo userInfo, BindingResult result) throws Exception {
    validator.validate(userInfo, result);

    if (result.hasErrors()) {
        ModelMap model = new ModelMap();
        this.setReferenceData(request, model);
        return new ModelAndView("edit_user", model);
    }//from  w  w w  .  j a va 2 s  .co m
    String userId = request.getParameter("select_user");

    userInfo.getUser().setUpdater(getUser(request).getUsername());
    // Updates only User
    if (!usersService.update(userInfo.getUser())) {
        throw new Exception("Updating user failed.");
    }
    // Updates only UserInfor
    if (!usersService.update(userInfo)) {
        throw new Exception("Updating user info failed.");
    }

    HttpSession session = request.getSession();
    session.removeAttribute("user");
    session.setAttribute("user", usersService.getUser(request.getRemoteUser()));

    return new ModelAndView("redirect:userowner.htm?select_user=" + userId);
}