本文整理匯總了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();
}
}
}
示例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
}
}
示例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;
}
示例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...");
}
示例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;
}
示例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) {
}
}
示例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;
}
示例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);
}
示例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");
}
示例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();
}