Example usage for javax.servlet.http HttpServletRequest removeAttribute

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

Introduction

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

Prototype

public void removeAttribute(String name);

Source Link

Document

Removes an attribute from this request.

Usage

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

/**
 * tH??[h??U???s?B/* ww w  .  jav a 2 s  . c om*/
 * <p>
 *   tH??[h??U?AT?[o?tO
 *   ???B<br>
 *   ?J??AdoDetamineForward()?B
 * </p>
 *
 * @param mapping ANV}bsO
 * @param form ANVtH?[
 * @param req <code>HTTP</code>NGXg
 * @param res <code>HTTP</code>X|X
 * @return J??
 */
@Override
public ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest req,
        HttpServletResponse res) {
    if (log.isDebugEnabled()) {
        log.debug("doExecute() called.");
    }
    // NGXgLZtO?mF?A
    // cancelled()?\bh?s?B
    if (isCancelled(req)) {
        ActionForward af = cancelled(mapping, form, req, res);
        if (af != null) {
            return af;
        }
    }

    if (event == null) {
        // eventw?A"event"ftHg??B
        event = "event";
    }

    String forward = doDetermineForward(req.getParameterMap(), event);

    ActionForward actionForward = null;
    if ("#input".equalsIgnoreCase(forward)) {
        actionForward = new ActionForward(mapping.getInput());
    } else {
        actionForward = mapping.findForward(forward);
    }

    // tH??[h????A"default" w
    // ANVtH??[hp?B
    if (actionForward == null) {
        if (log.isWarnEnabled()) {
            log.warn("forward name[" + forward + "] is invalid by user request.");
        }
        actionForward = mapping.findForward(FORWARD_DEFAULT);
    }

    // tH??[h??`FbNL
    // THRU_FILTERtO??
    // T?[o?
    req.removeAttribute(ServerBlockageControlFilter.SERVER_BLOCKAGE_THRU_KEY);
    // ?
    req.removeAttribute(BlockageControlFilter.BLOCKAGE_THRU_KEY);

    if (log.isDebugEnabled()) {
        log.debug("forward = " + forward + " (" + ((actionForward == null) ? "null" : actionForward.getPath())
                + ")");
    }
    return actionForward;
}

From source file:com.sinosoft.one.mvc.MvcFilter.java

protected void supportsMvcpipe(final HttpServletRequest httpRequest) {
    // ?mvcpipe??mvcpipe"Cannot forward after response has been committed"
    // @see com.sinosoft.one.mvc.web.portal.impl.PortalWaitInterceptor

    //        String windowNames = (String)httpRequest.getAttribute(MvcConstants.WINDOW_ATTR+".names");
    String windowName = (String) httpRequest.getAttribute(MvcConstants.WINDOW_ATTR + ".name");
    if (StringUtils.isNotBlank(windowName)) {

        Object window = httpRequest.getAttribute(MvcConstants.WINDOW_ATTR + "." + windowName);

        if (window != null && window.getClass().getName().startsWith("com.sinosoft.one.mvc.web.portal")) {
            httpRequest.setAttribute(MvcConstants.PIPE_WINDOW_IN, Boolean.TRUE);
            if (logger.isDebugEnabled()) {
                try {
                    logger.debug(/* w  w  w.j ava2s .  c  o m*/
                            "notify window '" + httpRequest.getAttribute("$$one-mvc-portal.window.name") + "'");
                } catch (Exception e) {
                    logger.error("", e);
                }
            }
            synchronized (window) {
                window.notifyAll();
                httpRequest.removeAttribute(MvcConstants.WINDOW_ATTR + ".name");
            }
        }
    }
    // Object window = httpRequest.getAttribute(MvcConstants.WINDOW_ATTR);

}

From source file:org.zkoss.zk.grails.web.ZKGrailsPageFilter.java

@Override
public void doFilter(ServletRequest rq, ServletResponse rs, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) rq;
    HttpServletResponse response = (HttpServletResponse) rs;
    ServletContext servletContext = filterConfig.getServletContext();

    SiteMeshWebAppContext webAppContext = new SiteMeshWebAppContext(request, response, servletContext);

    if (filterAlreadyAppliedForRequest(request)) {
        // Prior to Servlet 2.4 spec, it was unspecified whether the filter should be called again upon an include().
        chain.doFilter(request, response);
        return;// w ww  .  j  av  a 2s.  co  m
    }

    if (isZUL(request)) {
        //
        // TODO if disable live
        //
        Content content = obtainContent(contentProcessor, webAppContext, request, response, chain);
        if (content == null || response.isCommitted()) {
            return;
        }
        Content content2 = applyLive(request, content);
        new GrailsNoDecorator().render(content2, webAppContext);
        return;
    }

    if (isZK(request)) {
        chain.doFilter(request, response);
        return;
    }

    if (!contentProcessor.handles(webAppContext)) {
        // Optimization: If the content doesn't need to be processed, bypass SiteMesh.
        chain.doFilter(request, response);
        return;
    }

    // clear the page in case it is already present
    request.removeAttribute(RequestConstants.PAGE);

    if (containerTweaks.shouldAutoCreateSession()) {
        request.getSession(true);
    }

    boolean dispatched = false;
    try {
        persistenceInterceptor.init();
        Content content = obtainContent(contentProcessor, webAppContext, request, response, chain);
        if (content == null || response.isCommitted()) {
            return;
        }
        // applyLive(request, content);
        detectContentTypeFromPage(content, response);
        com.opensymphony.module.sitemesh.Decorator decorator = decoratorMapper.getDecorator(request,
                GSPSitemeshPage.content2htmlPage(content));
        if (decorator instanceof Decorator) {
            ((Decorator) decorator).render(content, webAppContext);
        } else {
            new OldDecorator2NewDecorator(decorator).render(content, webAppContext);
        }
        dispatched = true;
    } catch (IllegalStateException e) {
        // Some containers (such as WebLogic) throw an IllegalStateException when an error page is served.
        // It may be ok to ignore this. However, for safety it is propegated if possible.
        if (!containerTweaks.shouldIgnoreIllegalStateExceptionOnErrorPage()) {
            throw e;
        }
    } finally {
        if (!dispatched) {
            // an error occured
            request.setAttribute(ALREADY_APPLIED_KEY, null);
        }
        if (persistenceInterceptor.isOpen()) {
            persistenceInterceptor.flush();
            persistenceInterceptor.destroy();
        }
    }
}

From source file:nl.strohalm.cyclos.struts.CyclosRequestProcessor.java

/**
 * If the given {@link ForwardConfig} will actually include something (probably a JSP), open a new read-only transaction, so lazy-loading and data
 * iteration will work//  ww  w. ja  v a  2s  . com
 */
@Override
protected void processForwardConfig(final HttpServletRequest request, final HttpServletResponse response,
        final ForwardConfig forward) throws IOException, ServletException {
    final ExecutionResult result = (ExecutionResult) request.getAttribute(EXECUTION_RESULT_KEY);
    final boolean isInclude = forward != null && !forward.getRedirect();
    final boolean needsReadOnlyConnection = isInclude && !result.longTransaction;

    if (needsReadOnlyConnection) {
        // When needed, open a new read-only connection for the include
        openReadOnlyConnection(request);
    }

    // The top-most invocation will manage transaction. Any includes won't
    final boolean managesTransaction = !noTransaction(request);
    if (managesTransaction) {
        request.setAttribute(NO_TRANSACTION_KEY, true);
    }

    try {
        super.processForwardConfig(request, response, forward);
    } catch (final IllegalStateException e) {
        LOG.warn("Error processing the forward to " + forward.getPath());
    } finally {
        if (managesTransaction) {
            // Remove the attribute, otherwise, the top-most invocations of commitOrRollbackTransaction() or rollbackTransaction() will do nothing
            request.removeAttribute(NO_TRANSACTION_KEY);
        }
        if (result.longTransaction) {
            // Close the long running read-write connection
            result.commit = false;
            commitOrRollbackTransaction(request);
        } else if (needsReadOnlyConnection) {
            rollbackReadOnlyConnection(request);
        }
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.ViewClassesActionNew.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws FenixActionException {
    final ActionErrors errors = new ActionErrors();

    try {//ww w.j  a  v a 2  s .  c om
        super.execute(mapping, form, request, response);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

    Boolean inEnglish = (Boolean) request.getAttribute("inEnglish");
    if (inEnglish == null) {
        inEnglish = getLocale(request).getLanguage().equals(Locale.ENGLISH.getLanguage());
    }
    request.setAttribute("inEnglish", inEnglish);

    // index
    Integer index = (Integer) request.getAttribute("index");
    request.setAttribute("index", index);

    // degreeID
    String degreeId = (String) request.getAttribute("degreeID");
    request.setAttribute("degreeID", degreeId);

    // degreeCurricularPlanID
    String degreeCurricularPlanId = (String) request.getAttribute("degreeCurricularPlanID");
    request.setAttribute("degreeCurricularPlanID", degreeCurricularPlanId);
    final DegreeCurricularPlan degreeCurricularPlan = FenixFramework.getDomainObject(degreeCurricularPlanId);
    if (!degreeCurricularPlan.getDegree().getExternalId().equals(degreeId)) {
        throw new FenixActionException();
    } else {
        request.setAttribute("degree", degreeCurricularPlan.getDegree());
    }

    // lista
    List<LabelValueBean> executionPeriodsLabelValueList = buildExecutionPeriodsLabelValueList(
            degreeCurricularPlanId);
    if (executionPeriodsLabelValueList.size() > 1) {
        request.setAttribute("lista", executionPeriodsLabelValueList);
    } else {
        request.removeAttribute("lista");
    }

    // indice
    final DynaActionForm escolherContextoForm = (DynaActionForm) form;
    String indice = (String) escolherContextoForm.get("indice");
    escolherContextoForm.set("indice", indice);
    request.setAttribute("indice", indice);

    InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) request
            .getAttribute(PresentationConstants.EXECUTION_PERIOD);
    request.setAttribute(PresentationConstants.EXECUTION_PERIOD, infoExecutionPeriod);
    request.setAttribute(PresentationConstants.EXECUTION_PERIOD_OID,
            infoExecutionPeriod.getExternalId().toString());

    final ExecutionSemester executionSemester = FenixFramework
            .getDomainObject(infoExecutionPeriod.getExternalId());
    ExecutionDegree executionDegree = degreeCurricularPlan
            .getExecutionDegreeByYear(executionSemester.getExecutionYear());
    if (executionDegree != null) {
        // infoExecutionDegree
        InfoExecutionDegree infoExecutionDegree = InfoExecutionDegree.newInfoFromDomain(executionDegree);
        RequestUtils.setExecutionDegreeToRequest(request, infoExecutionDegree);

        request.setAttribute(PresentationConstants.INFO_DEGREE_CURRICULAR_PLAN,
                infoExecutionDegree.getInfoDegreeCurricularPlan());

        List<InfoClass> classList = LerTurmas.run(infoExecutionDegree, infoExecutionPeriod, null);

        if (!classList.isEmpty()) {
            ComparatorChain comparatorChain = new ComparatorChain();
            comparatorChain.addComparator(new BeanComparator("anoCurricular"));
            comparatorChain.addComparator(new BeanComparator("nome"));
            Collections.sort(classList, comparatorChain);

            request.setAttribute("classList", classList);
        }
    }

    return mapping.findForward("Sucess");
}

From source file:org.apache.struts.webapp.example2.LogonAction.java

/**
 * Process the specified HTTP request, and create the corresponding HTTP
 * response (or forward to another web component that will create it).
 * Return an <code>ActionForward</code> instance describing where and how
 * control should be forwarded, or <code>null</code> if the response has
 * already been completed.// w ww. ja v a 2 s.co  m
 *
 * @param mapping The ActionMapping used to select this instance
 * @param form The optional ActionForm bean for this request (if any)
 * @param request The HTTP request we are processing
 * @param response The HTTP response we are creating
 *
 * @exception Exception if business logic throws an exception
 */
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    // Extract attributes we will need
    Locale locale = getLocale(request);
    MessageResources messages = getResources(request);
    User user = null;

    // Validate the request parameters specified by the user
    ActionErrors errors = new ActionErrors();
    String username = (String) PropertyUtils.getSimpleProperty(form, "username");
    String password = (String) PropertyUtils.getSimpleProperty(form, "password");
    UserDatabase database = (UserDatabase) servlet.getServletContext().getAttribute(Constants.DATABASE_KEY);
    if (database == null)
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.database.missing"));
    else {
        user = getUser(database, username);
        if ((user != null) && !user.getPassword().equals(password))
            user = null;
        if (user == null)
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.password.mismatch"));
    }

    // Report any errors we have discovered back to the original form
    if (!errors.isEmpty()) {
        saveErrors(request, errors);
        return (mapping.getInputForward());
    }

    // Save our logged-in user in the session
    HttpSession session = request.getSession();
    session.setAttribute(Constants.USER_KEY, user);
    if (log.isDebugEnabled()) {
        log.debug("LogonAction: User '" + user.getUsername() + "' logged on in session " + session.getId());
    }

    // Remove the obsolete form bean
    if (mapping.getAttribute() != null) {
        if ("request".equals(mapping.getScope()))
            request.removeAttribute(mapping.getAttribute());
        else
            session.removeAttribute(mapping.getAttribute());
    }

    // Forward control to the specified success URI
    return (mapping.findForward("success"));

}

From source file:org.dspace.webmvc.controller.admin.EditCommunitiesController.java

@RequestMapping(method = RequestMethod.POST, params = "submit_confirm_delete_collection")
protected String confirmDeleteCollection(@RequestAttribute Context context, ModelMap model,
        HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, SQLException, AuthorizeException {

    Collection collection = Collection.find(context, Util.getIntParameter(request, "collection_id"));
    model.addAttribute("collection", collection);
    Community community = Community.find(context, Util.getIntParameter(request, "community_id"));
    model.addAttribute("community", community);

    // Delete the collection
    community.removeCollection(collection);
    // remove the collection object from the request, so that the user
    // will be redirected on the community home page
    request.removeAttribute("collection");

    // Commit changes to DB
    context.commit();//from w ww . j  av a 2  s  .co m
    // Show main control page
    return showControls(context, model, request, response);

}

From source file:com.jsmartframework.web.manager.BeanHandler.java

private void finalizeWebSecurity(Object listener, HttpServletRequest request) {
    executePreDestroy(listener);/* w  ww .ja v a  2  s  . c  o m*/
    WebSecurity webSecurity = listener.getClass().getAnnotation(WebSecurity.class);
    request.removeAttribute(HELPER.getClassName(webSecurity, listener.getClass()));
}

From source file:org.jasig.portal.layout.StylesheetUserPreferencesServiceImpl.java

@Transactional
@Override/*from w  w  w  .j av a 2 s .  co  m*/
public void clearOutputProperties(HttpServletRequest request, PreferencesScope prefScope) {
    final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request,
            prefScope);

    final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request,
            stylesheetPreferencesKey);
    if (stylesheetUserPreferences != null) {
        stylesheetUserPreferences.clearOutputProperties();
        this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
    }

    final HttpSession session = request.getSession(false);
    if (session != null) {
        session.removeAttribute(OUTPUT_PROPERTIES_KEY + stylesheetPreferencesKey.toString());
    }

    request.removeAttribute(OUTPUT_PROPERTIES_KEY + stylesheetPreferencesKey.toString());
}