Example usage for javax.servlet.http HttpSession removeAttribute

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

Introduction

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

Prototype

public void removeAttribute(String name);

Source Link

Document

Removes the object bound with the specified name from this session.

Usage

From source file:jp.terasoluna.fw.web.struts.actions.ClearSessionAction.java

/**
 * ZbVNA?s?AtH??[h?B/*from  w w  w  . j  av  a2  s. c o  m*/
 * <p>
 *  ???L?[P???A
 *  J??p?A???I?B
 * </p>
 * @param mapping ANV}bsO
 * @param form ANVtH?[
 * @param request <code>HTTP</code>NGXg
 * @param response <code>HTTP</code>X|X
 * @return J??
 */
@Override
public ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {

    HttpSession session = request.getSession();

    if (clearSessionKeys != null) {
        for (int cnt = 0; cnt < clearSessionKeys.size(); cnt++) {
            String sKey = (String) clearSessionKeys.get(cnt);
            if (log.isDebugEnabled()) {
                log.debug("removing [" + sKey + "] from HttpSession");
            }
            //ZbV???s
            session.removeAttribute(sKey);
        }
    }

    // p??[^??itH??[h??j
    String path = mapping.getParameter();

    if (path == null) {
        // p??[^?????A(404)G?[p
        try {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        } catch (IOException e) {
            log.error("Error page(404) forwarding failed.");

            throw new SystemException(e, FORWARD_ERRORPAGE_ERROR);
        }
        return null;
    }

    // ANVtH??[h??
    ActionForward retVal = new ActionForward(path);

    return retVal;

}

From source file:ch.systemsx.cisd.openbis.plugin.generic.client.web.server.GenericClientService.java

private void cleanUploadedFiles(final String sessionKey, HttpSession session, UploadedFilesBean uploadedFiles) {
    if (uploadedFiles != null) {
        uploadedFiles.deleteTransferredFiles();
    }/*from w w w.  j  a v a2  s .  c o m*/
    if (session != null) {
        session.removeAttribute(sessionKey);
    }
}

From source file:org.onebusaway.nyc.vehicle_tracking.webapp.controllers.VehicleLocationSimulationController.java

@RequestMapping(value = "/vehicle-location-simulation!set-calendar-offset.do", method = RequestMethod.GET)
public ModelAndView setCalendarOffser(HttpSession session,
        @RequestParam(required = false) String calendarOffset) {
    if (calendarOffset != null)
        session.setAttribute(CALENDAR_OFFSET_KEY, calendarOffset);
    else//from  www .j  av  a  2  s .  c  o m
        session.removeAttribute(CALENDAR_OFFSET_KEY);
    return new ModelAndView("redirect:/vehicle-location-simulation.do");
}

From source file:easycare.web.password.ChangePasswordController.java

private boolean updatePasswordToken(HttpSession session) {
    String tokenKey = (String) session.getAttribute(USER_PASSWORD_TOKEN_ID_KEY);
    if (tokenKey != null) {
        UserPasswordToken token = userPasswordService.findUserPasswordToken(tokenKey);
        if (!userPasswordService.isTokenValid(token)) {
            return false;
        }/*from  www .j a v a 2s.c  o  m*/
        userPasswordService.usePasswordToken(token);
        session.removeAttribute(USER_PASSWORD_TOKEN_ID_KEY);
    }
    return true;
}

From source file:gov.nih.nci.ncicb.cadsr.common.struts.common.BaseDispatchAction.java

/**
 * Sets default method name if no method is specified
 *
 * @return ActionForward/*from w  w w . java2  s .  com*/
 *
 * @throws Exception
 */
protected ActionForward dispatchMethod(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response, String name) throws Exception {
    if ((name == null) || name.equals("")) {
        name = DEFAULT_METHOD;
    }

    try {
        return super.dispatchMethod(mapping, form, request, response, name);
    } catch (Throwable throwable) {
        HttpSession session = request.getSession();
        String userName = request.getRemoteUser();
        if (userName == null)
            userName = "";
        Collection keys = (Collection) session.getAttribute(this.CLEAR_SESSION_KEYS);
        if (keys != null) {
            Iterator it = keys.iterator();
            while (it.hasNext()) {
                session.removeAttribute((String) it.next());
            }
        }
        if (log.isFatalEnabled()) {
            log.fatal(userName + ": Exception in dispatchMethod in method " + name, throwable);
        }
        saveMessage(ERROR_FATAL, request);
        throw new FatalException(throwable);
    }
}

From source file:cn.vlabs.umt.ui.actions.BatchCreateAction.java

private void cleanup(HttpServletRequest request) {
    HttpSession session = request.getSession();
    RecordFile records = (RecordFile) session.getAttribute("batch.records");
    if (records != null) {
        String datadir = records.getDatadir();
        try {//  w  w w  . j ava  2s  .c  o  m
            FileUtils.deleteDirectory(new File(datadir));
        } catch (IOException e) {
            log.info(":" + e.getMessage());
        }
        session.removeAttribute("batch.records");
        session.removeAttribute("batch.total");
    }
}

From source file:fr.paris.lutece.plugins.workflow.modules.editrecord.web.EditRecordApp.java

/**
 * Get the edit record page/*from w w  w.j a  va  2s  .  c  o  m*/
 * @param request the HTTP request
 * @param editRecord the edit record
 * @return a XPage
 * @throws SiteMessageException a site message if there is a problem
 */
private XPage getEditRecordPage(HttpServletRequest request, EditRecord editRecord) throws SiteMessageException {
    XPage page = new XPage();

    List<IEntry> listEntries = _editRecordService.getListEntriesToEdit(request,
            editRecord.getListEditRecordValues());

    /**
     * Map of <idEntry, RecordFields>
     *         1) The user has uploaded/deleted a file
     *                 - The updated map is stored in the session
     *  2) The user has not uploaded/delete a file
     *          - The map is filled with the data from the database
     *          - The asynchronous uploaded files map is reinitialized
     */
    Map<String, List<RecordField>> mapRecordFields = null;

    // Get the map of <idEntry, RecordFields from session if it exists : 
    /** 1) Case when the user has uploaded a file, the the map is stored in the session */
    HttpSession session = request.getSession(false);

    if (session != null) {
        mapRecordFields = (Map<String, List<RecordField>>) session
                .getAttribute(EditRecordConstants.SESSION_EDIT_RECORD_LIST_SUBMITTED_RECORD_FIELDS);
        // IMPORTANT : Remove the map from the session
        session.removeAttribute(EditRecordConstants.SESSION_EDIT_RECORD_LIST_SUBMITTED_RECORD_FIELDS);
    }

    // Get the map <idEntry, RecordFields> classically from the database
    /** 2) The user has not uploaded/delete a file */
    if (mapRecordFields == null) {
        Plugin pluginDirectory = PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME);
        mapRecordFields = _editRecordService.getMapIdEntryListRecordField(listEntries,
                editRecord.getIdHistory());
        // Reinit the asynchronous uploaded file map
        DirectoryAsynchronousUploadHandler.getHandler().reinitMap(request, mapRecordFields, pluginDirectory);
    }

    Record record = _editRecordService.getRecordFromIdHistory(editRecord.getIdHistory());

    Map<String, Object> model = new HashMap<String, Object>();
    model.put(EditRecordConstants.MARK_EDIT_RECORD, editRecord);
    model.put(EditRecordConstants.MARK_LIST_ENTRIES, listEntries);
    model.put(EditRecordConstants.MARK_MAP_ID_ENTRY_LIST_RECORD_FIELD, mapRecordFields);
    model.put(EditRecordConstants.MARK_WEBAPP_URL, AppPathService.getBaseUrl(request));
    model.put(EditRecordConstants.MARK_LOCALE, request.getLocale());
    model.put(EditRecordConstants.MARK_URL_RETURN,
            request.getParameter(EditRecordConstants.PARAMETER_URL_RETURN));
    model.put(EditRecordConstants.MARK_SIGNATURE,
            request.getParameter(EditRecordConstants.PARAMETER_SIGNATURE));
    model.put(EditRecordConstants.MARK_TIMESTAMP,
            request.getParameter(EditRecordConstants.PARAMETER_TIMESTAMP));

    if (record != null) {
        model.put(EditRecordConstants.MARK_ID_DIRECTORY_RECORD, record.getIdRecord());
    }

    HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_EDIT_RECORD, request.getLocale(), model);

    page.setTitle(I18nService.getLocalizedString(EditRecordConstants.PROPERTY_XPAGE_EDIT_RECORD_PAGETITLE,
            request.getLocale()));
    page.setPathLabel(I18nService.getLocalizedString(EditRecordConstants.PROPERTY_XPAGE_EDIT_RECORD_PATHLABEL,
            request.getLocale()));
    page.setContent(template.getHtml());

    return page;
}

From source file:net.triptech.buildulator.FlashScopeFilter.java

/**
 * The doFilterInternal method./*from  w w w.  ja v a 2s  .c  om*/
 *
 * @param request the http servlet request
 * @param response the http servlet response
 * @param filterChain the filter chain
 * @throws ServletException the servlet exception
 * @throws IOException the IO exception
 */
@Override
protected final void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain filterChain) throws ServletException, IOException {
    HttpSession session = request.getSession(false);
    if (session != null) {
        Map<?, ?> flash = (Map<?, ?>) session.getAttribute(FlashScope.FLASH_SCOPE_ATTRIBUTE);
        if (flash != null) {
            for (Object key : flash.keySet()) {
                Object value = flash.get(key);
                Object currentValue = request.getAttribute((String) key);

                if (currentValue == null) {
                    request.setAttribute((String) key, value);
                }
            }
            session.removeAttribute(FlashScope.FLASH_SCOPE_ATTRIBUTE);
        }
    }
    filterChain.doFilter(request, response);
}

From source file:org.dataconservancy.ui.stripes.UpdateCollectionActionBean.java

/**
 * Removes the Collection object from the HTTP session.
 *//*from   w w w . j  a v a2 s .  c om*/
private void clearCollection() {
    HttpSession ses = getContext().getRequest().getSession();
    ses.removeAttribute(collectionId);
}

From source file:com.iisigroup.cap.base.handler.CheckTimeoutHandler.java

@SuppressWarnings("unchecked")
public Result checkClosePage(Request request) throws CapException {
    AjaxFormResult result = new AjaxFormResult();
    HttpServletRequest sreq = (HttpServletRequest) request.getServletRequest();

    String refPath = sreq.getHeader("referer");
    refPath = StringEscapeUtils.unescapeHtml(refPath);

    // boolean isNewSes = sreq.getSession(false).isNew();

    HttpSession session = sreq.getSession(false);
    Map<String, String> map = (Map<String, String>) session.getAttribute(TOCM);
    Map<String, Object> pmor = (Map<String, Object>) session.getAttribute("pmorq");
    if (pmor != null) {
        String cleanPreMoice = request.get("CLNPREMOICA");
        if ("Y".equals(cleanPreMoice)) {
            session.removeAttribute("pmorq");
        }/*from w w  w.  j  a  v a  2s  .  co m*/
    }
    if (map != null) {
        String curPage = request.get(CCPAGE_NO);
        if (map.containsKey(curPage)) {
            map.remove(curPage);
            session.setAttribute(TOCM, map);
        }
    }

    // if(refPath.indexOf("moica")!=-1){
    // String SERVER_O_REQUEST = "sorq";
    // session.setAttribute(SERVER_O_REQUEST, null);
    // }
    return result;
}