当前位置: 首页>>代码示例>>Java>>正文


Java ServletContext.removeAttribute方法代码示例

本文整理汇总了Java中javax.servlet.ServletContext.removeAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java ServletContext.removeAttribute方法的具体用法?Java ServletContext.removeAttribute怎么用?Java ServletContext.removeAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.ServletContext的用法示例。


在下文中一共展示了ServletContext.removeAttribute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: closeWebApplicationContext

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Close Spring's web application context for the given servlet context. If
 * the default {@link #loadParentContext(ServletContext)} implementation,
 * which uses ContextSingletonBeanFactoryLocator, has loaded any shared
 * parent context, release one reference to that shared parent context.
 * <p>If overriding {@link #loadParentContext(ServletContext)}, you may have
 * to override this method as well.
 * @param servletContext the ServletContext that the WebApplicationContext runs in
 */
public void closeWebApplicationContext(ServletContext servletContext) {
	servletContext.log("Closing Spring root WebApplicationContext");
	try {
		if (this.context instanceof ConfigurableWebApplicationContext) {
			((ConfigurableWebApplicationContext) this.context).close();
		}
	}
	finally {
		ClassLoader ccl = Thread.currentThread().getContextClassLoader();
		if (ccl == ContextLoader.class.getClassLoader()) {
			currentContext = null;
		}
		else if (ccl != null) {
			currentContextPerThread.remove(ccl);
		}
		servletContext.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
		if (this.parentContextRef != null) {
			this.parentContextRef.release();
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:ContextLoader.java

示例2: contextDestroyed

import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
public void contextDestroyed(ServletContextEvent sce) {
  log.info("ModelManagerListener destroying");
  // Slightly paranoid; remove objects from app scope manually
  ServletContext context = sce.getServletContext();
  for (Enumeration<String> names = context.getAttributeNames(); names.hasMoreElements();) {
    context.removeAttribute(names.nextElement());
  }

  close();

  // Hacky, but prevents Tomcat from complaining that ZK's cleanup thread 'leaked' since
  // it has a short sleep at its end
  try {
    Thread.sleep(1000);
  } catch (InterruptedException ie) {
    // continue
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:20,代码来源:ModelManagerListener.java

示例3: stopInternal

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Stop associated {@link ClassLoader} and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void stopInternal() throws LifecycleException {

    if (log.isDebugEnabled())
        log.debug(sm.getString("webappLoader.stopping"));

    setState(LifecycleState.STOPPING);

    // Remove context attributes as appropriate
    if (container instanceof Context) {
        ServletContext servletContext =
            ((Context) container).getServletContext();
        servletContext.removeAttribute(Globals.CLASS_PATH_ATTR);
    }

    // Throw away our current class loader
    if (classLoader != null) {
        ((Lifecycle) classLoader).stop();
        DirContextURLStreamHandler.unbind(classLoader);
    }

    try {
        StandardContext ctx=(StandardContext)container;
        String contextName = ctx.getName();
        if (!contextName.startsWith("/")) {
            contextName = "/" + contextName;
        }
        ObjectName cloname = new ObjectName
            (MBeanUtils.getDomain(ctx) + ":type=WebappClassLoader,context="
             + contextName + ",host=" + ctx.getParent().getName());
        Registry.getRegistry(null, null).unregisterComponent(cloname);
    } catch (Exception e) {
        log.error("LifecycleException ", e);
    }

    classLoader = null;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:45,代码来源:WebappLoader.java

示例4: contextDestroyed

import javax.servlet.ServletContext; //导入方法依赖的package包/类
public void contextDestroyed(ServletContext context) {
	try {
		log.info("Shutting down Eureka Server..");
		context.removeAttribute(EurekaServerContext.class.getName());

		destroyEurekaServerContext();
		destroyEurekaEnvironment();

	}
	catch (Throwable e) {
		log.error("Error shutting down eureka", e);
	}
	log.info("Eureka Service is now shutdown...");
}
 
开发者ID:dyc87112,项目名称:didi-eureka-server,代码行数:15,代码来源:EurekaServerBootstrap.java

示例5: stop

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Stop this component, finalizing our associated class loader.
 *
 * @exception LifecycleException if a lifecycle error occurs
 */
public void stop() throws LifecycleException {

    // Validate and update our current component state
    if (!started)
        throw new LifecycleException
            (sm.getString("webappLoader.notStarted"));
    if (debug >= 1)
        log(sm.getString("webappLoader.stopping"));
    lifecycle.fireLifecycleEvent(STOP_EVENT, null);
    started = false;

    // Stop our background thread if we are reloadable
    if (reloadable)
        threadStop();

    // Remove context attributes as appropriate
    if (container instanceof Context) {
        ServletContext servletContext =
            ((Context) container).getServletContext();
        servletContext.removeAttribute(Globals.CLASS_PATH_ATTR);
    }

    // Throw away our current class loader
    if (classLoader instanceof Lifecycle)
        ((Lifecycle) classLoader).stop();
    DirContextURLStreamHandler.unbind((ClassLoader) classLoader);
    classLoader = null;

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:35,代码来源:WebappLoader.java

示例6: contextDestroyed

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void contextDestroyed(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    try {
        context.removeAttribute("upTime");
    } catch (Exception e) {
    }
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:12,代码来源:ContextListener.java

示例7: stopInternal

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Stop associated {@link ClassLoader} and implement the requirements of
 * {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
 *
 * @exception LifecycleException
 *                if this component detects a fatal error that prevents this
 *                component from being used
 */
@Override
protected void stopInternal() throws LifecycleException {

	if (log.isDebugEnabled())
		log.debug(sm.getString("webappLoader.stopping"));

	setState(LifecycleState.STOPPING);

	// Remove context attributes as appropriate
	if (container instanceof Context) {
		ServletContext servletContext = ((Context) container).getServletContext();
		servletContext.removeAttribute(Globals.CLASS_PATH_ATTR);
	}

	// Throw away our current class loader
	if (classLoader != null) {
		((Lifecycle) classLoader).stop();
		DirContextURLStreamHandler.unbind(classLoader);
	}

	try {
		StandardContext ctx = (StandardContext) container;
		String contextName = ctx.getName();
		if (!contextName.startsWith("/")) {
			contextName = "/" + contextName;
		}
		ObjectName cloname = new ObjectName(MBeanUtils.getDomain(ctx) + ":type=WebappClassLoader,context="
				+ contextName + ",host=" + ctx.getParent().getName());
		Registry.getRegistry(null, null).unregisterComponent(cloname);
	} catch (Exception e) {
		log.error("LifecycleException ", e);
	}

	classLoader = null;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:44,代码来源:WebappLoader.java

示例8: testBug54239

import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Test
public void testBug54239() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    Context ctx = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
    tomcat.start();

    ServletContext context = ctx.getServletContext();

    ELInterpreter interpreter =
            ELInterpreterFactory.getELInterpreter(context);
    Assert.assertNotNull(interpreter);
    Assert.assertTrue(interpreter instanceof DefaultELInterpreter);

    context.removeAttribute(ELInterpreter.class.getName());

    context.setAttribute(ELInterpreter.class.getName(),
            SimpleELInterpreter.class.getName());
    interpreter = ELInterpreterFactory.getELInterpreter(context);
    Assert.assertNotNull(interpreter);
    Assert.assertTrue(interpreter instanceof SimpleELInterpreter);

    context.removeAttribute(ELInterpreter.class.getName());

    SimpleELInterpreter simpleInterpreter = new SimpleELInterpreter();
    context.setAttribute(ELInterpreter.class.getName(), simpleInterpreter);
    interpreter = ELInterpreterFactory.getELInterpreter(context);
    Assert.assertNotNull(interpreter);
    Assert.assertTrue(interpreter instanceof SimpleELInterpreter);
    Assert.assertTrue(interpreter == simpleInterpreter);

    context.removeAttribute(ELInterpreter.class.getName());

    ctx.stop();
    ctx.addApplicationListener(Bug54239Listener.class.getName());
    ctx.start();

    interpreter = ELInterpreterFactory.getELInterpreter(ctx.getServletContext());
    Assert.assertNotNull(interpreter);
    Assert.assertTrue(interpreter instanceof SimpleELInterpreter);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:43,代码来源:TestELInterpreterFactory.java

示例9: doListCollections

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 *  Handles a request to get a the available collections. <p>
 *
 *  Error Exception Conditions: <br>
 *  badArgument - The request includes illegal arguments.
 *
 * @param  request        The HTTP request
 * @param  response       The HTTP response
 * @param  rm             The RepositoryManager used
 * @param  df             The bean
 * @param  mapping        ActionMapping used
 * @return                An ActionForward to the JSP page that will handle the response
 * @exception  Exception  If error.
 */
protected ActionForward doListCollections(
                                          HttpServletRequest request,
                                          HttpServletResponse response,
                                          RepositoryManager rm,
                                          DDSServicesForm df,
                                          ActionMapping mapping)
	 throws Exception {

	ServletContext context = servlet.getServletContext();

	// If a different vocabInterface is requested, return it instead of the cache
	String vocabInterface = request.getParameter("vocabInterface");
	if (vocabInterface != null) {
		if (!vocabInterface.equals("dds.descr.en-us")) {
			df.setVocabInterface(vocabInterface);
			context.removeAttribute(getListCollectionsCacheKey());
		}
	}

	// Return the cached response if nothing has changed, otherwise update the cache
	if (rm.getSetStatusModifiedTime() > setStatusModifiedTime || rm.getIndexLastModifiedCount() > indexLastModifiedCount) {
		context.removeAttribute(getListCollectionsCacheKey());
		setStatusModifiedTime = rm.getSetStatusModifiedTime();
		prtln("removing coll cache key: " + getListCollectionsCacheKey());
		indexLastModifiedCount = rm.getIndexLastModifiedCount();
	}
	else if (context.getAttribute(getListCollectionsCacheKey()) != null) {
		// If nothing has changed and we've already got a cache, return it...
		return mapping.findForward("ddsservices.ListCollections");
	}

	// Records in the 'collect' collection are those that the Repository configures as collections:
	String query = "collection:0collect";

	// Sort by short title:
	Sort sortBy = new Sort( new SortField("/key//collectionRecord/general/shortTitle", SortField.STRING, false) );	
	
	ResultDocList results = rm.getIndex().searchDocs(query,sortBy);
	
	/* if (results != null) {
		Collections.sort(results, new LuceneFieldComparator("shorttitle", LuceneFieldComparator.ASCENDING));
	} */

	df.setResults(results);

	// Set up vocab
	//System.out.println("setting collection field...");
	df.setField("dlese_collect", "key");

	return mapping.findForward("ddsservices.ListCollections");
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:66,代码来源:DDSServicesAction.java

示例10: stop

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Stop this component, finalizing our associated class loader.
 *
 * @exception LifecycleException if a lifecycle error occurs
 */
public void stop() throws LifecycleException {

    // Validate and update our current component state
    if (!started)
        throw new LifecycleException
            (sm.getString("webappLoader.notStarted"));
    if (log.isDebugEnabled())
        log.debug(sm.getString("webappLoader.stopping"));
    lifecycle.fireLifecycleEvent(STOP_EVENT, null);
    started = false;

    // Remove context attributes as appropriate
    if (container instanceof Context) {
        ServletContext servletContext =
            ((Context) container).getServletContext();
        servletContext.removeAttribute(Globals.CLASS_PATH_ATTR);
    }

    // Throw away our current class loader
    if (classLoader instanceof Lifecycle)
        ((Lifecycle) classLoader).stop();
    DirContextURLStreamHandler.unbind((ClassLoader) classLoader);

    try {
        StandardContext ctx=(StandardContext)container;
        Engine eng=(Engine)ctx.getParent().getParent();
        String path = ctx.getPath();
        if (path.equals("")) {
            path = "/";
        }
        ObjectName cloname = new ObjectName
            (ctx.getEngineName() + ":type=WebappClassLoader,path="
             + path + ",host=" + ctx.getParent().getName());
        Registry.getRegistry(null, null).unregisterComponent(cloname);
    } catch (Throwable t) {
        log.error( "LifecycleException ", t );
    }

    classLoader = null;

    destroy();

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:49,代码来源:WebappLoader.java


注:本文中的javax.servlet.ServletContext.removeAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。