當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletContext.setAttribute方法代碼示例

本文整理匯總了Java中javax.servlet.ServletContext.setAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletContext.setAttribute方法的具體用法?Java ServletContext.setAttribute怎麽用?Java ServletContext.setAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.ServletContext的用法示例。


在下文中一共展示了ServletContext.setAttribute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import javax.servlet.ServletContext; //導入方法依賴的package包/類
static WsServerContainer init(ServletContext servletContext,
        boolean initBySciMechanism) {

    WsServerContainer sc = new WsServerContainer(servletContext);

    servletContext.setAttribute(
            Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE, sc);

    servletContext.addListener(new WsSessionListener(sc));
    // Can't register the ContextListener again if the ContextListener is
    // calling this method
    if (initBySciMechanism) {
        servletContext.addListener(new WsContextListener());
    }

    return sc;
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:18,代碼來源:WsSci.java

示例2: init

import javax.servlet.ServletContext; //導入方法依賴的package包/類
public void init() throws ServletException {
    
    if (getServletConfig().getInitParameter("timeout") != null) {
        timeout = Integer.parseInt(getServletConfig().getInitParameter("timeout"));
    }
    if (getServletConfig().getInitParameter("reconnectInterval") != null) {
        reconnectInterval = Integer.parseInt(getServletConfig().getInitParameter("reconnectInterval"));
    }

    ServletContext ctx = getServletConfig().getServletContext();
    if (ctx.getAttribute(TOMCAT_BAYEUX_ATTR)==null)
        ctx.setAttribute(TOMCAT_BAYEUX_ATTR,new TomcatBayeux());
    this.tb = (TomcatBayeux)ctx.getAttribute(TOMCAT_BAYEUX_ATTR);
    tb.setReconnectInterval(getReconnectInterval());

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:BayeuxServlet.java

示例3: registerWebApplicationScopes

import javax.servlet.ServletContext; //導入方法依賴的package包/類
/**
 * Register web-specific scopes ("request", "session", "globalSession", "application")
 * with the given BeanFactory, as used by the WebApplicationContext.
 * @param beanFactory the BeanFactory to configure
 * @param sc the ServletContext that we're running within
 */
public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory, ServletContext sc) {
	beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope());
	beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(false));
	beanFactory.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, new SessionScope(true));
	if (sc != null) {
		ServletContextScope appScope = new ServletContextScope(sc);
		beanFactory.registerScope(WebApplicationContext.SCOPE_APPLICATION, appScope);
		// Register as ServletContext attribute, for ContextCleanupListener to detect it.
		sc.setAttribute(ServletContextScope.class.getName(), appScope);
	}

	beanFactory.registerResolvableDependency(ServletRequest.class, new RequestObjectFactory());
	beanFactory.registerResolvableDependency(HttpSession.class, new SessionObjectFactory());
	beanFactory.registerResolvableDependency(WebRequest.class, new WebRequestObjectFactory());
	if (jsfPresent) {
		FacesDependencyRegistrar.registerFacesDependencies(beanFactory);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:WebApplicationContextUtils.java

示例4: contextInitialized

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void contextInitialized(ServletContextEvent e) {
	LOG.info("Creating Smaph context.");
	ServletContext context = e.getServletContext();
	context.setAttribute("nif-parser", new TurtleNIFDocumentParser());
	context.setAttribute("nif-creator", new TurtleNIFDocumentCreator());
	String watGcubeToken = context.getInitParameter(WAT_GCUBE_TOKEN);
	SmaphBuilder.initialize(watGcubeToken);
	try {
		context.setAttribute("wikipedia-api", new WikipediaInterfaceWAT.WikipediaInterfaceWATBuilder().gcubeToken(watGcubeToken).build());
	} catch (URISyntaxException e1) {
		e1.printStackTrace();
	}
	
	context.setAttribute("wiki-to-freebase", WikipediaToFreebase.open(context.getInitParameter(FREEBASE_DIR)));
	context.setAttribute("entity-to-anchors", EntityToAnchors.fromDB(context.getInitParameter(ENTITY_TO_ANCHORS_DB)));
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:18,代碼來源:SmaphContextListener.java

示例5: initModulePrefixes

import javax.servlet.ServletContext; //導入方法依賴的package包/類
/**
 * <p>Saves a String[] of module prefixes in the ServletContext under
 * Globals.MODULE_PREFIXES_KEY.  <strong>NOTE</strong> -
 * the "" prefix for the default module is not included in this list.</p>
 *
 * @param context The servlet context.
 * @since Struts 1.2
 */
protected void initModulePrefixes(ServletContext context) {
    ArrayList prefixList = new ArrayList();

    Enumeration names = context.getAttributeNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        if (!name.startsWith(Globals.MODULE_KEY)) {
            continue;
        }

        String prefix = name.substring(Globals.MODULE_KEY.length());
        if (prefix.length() > 0) {
            prefixList.add(prefix);
        }
    }

    String[] prefixes = (String[]) prefixList.toArray(new String[prefixList.size()]);
    context.setAttribute(Globals.MODULE_PREFIXES_KEY, prefixes);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:ActionServlet.java

示例6: doStart

import javax.servlet.ServletContext; //導入方法依賴的package包/類
protected void doStart(URL url) {
    // TODO jetty will by default enable keepAlive so the xml config has no effect now
    httpServer = httpBinder.bind(url, new RestHandler());

    ServletContext servletContext = ServletManager.getInstance().getServletContext(url.getPort());
    if (servletContext == null) {
        servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
    }
    if (servletContext == null) {
        throw new RpcException("No servlet context found. If you are using server='servlet', " +
                "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
    }

    servletContext.setAttribute(ResteasyDeployment.class.getName(), deployment);

    try {
        dispatcher.init(new SimpleServletConfig(servletContext));
    } catch (ServletException e) {
        throw new RpcException(e);
    }
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:22,代碼來源:DubboHttpServer.java

示例7: initMetrics

import javax.servlet.ServletContext; //導入方法依賴的package包/類
/**
 * Initializes Metrics.
 */
private void initMetrics(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    log.debug("Initializing Metrics registries");
    servletContext.setAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE,
        metricRegistry);
    servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY,
        metricRegistry);

    log.debug("Registering Metrics Filter");
    FilterRegistration.Dynamic metricsFilter = servletContext.addFilter("webappMetricsFilter",
        new InstrumentedFilter());

    metricsFilter.addMappingForUrlPatterns(disps, true, "/*");
    metricsFilter.setAsyncSupported(true);

    log.debug("Registering Metrics Servlet");
    ServletRegistration.Dynamic metricsAdminServlet =
        servletContext.addServlet("metricsServlet", new MetricsServlet());

    metricsAdminServlet.addMapping("/management/metrics/*");
    metricsAdminServlet.setAsyncSupported(true);
    metricsAdminServlet.setLoadOnStartup(2);
}
 
開發者ID:xm-online,項目名稱:xm-gate,代碼行數:26,代碼來源:WebConfigurer.java

示例8: invoke

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public int invoke(Request rqst, Response rspns) throws IOException,
        ServletException {
    if (!isStarted()) {
        try {
            start();
        } catch (LifecycleException ex) {
            throw new ServletException(ex);
        }
    }
    rqst.setNote(CatalinaAdapter.REQUEST_TIME, System.currentTimeMillis());
    if (!alreadySetLogbackStatusManager) {
        alreadySetLogbackStatusManager = true;
        org.apache.catalina.Context tomcatContext = rqst.getContext();
        if (tomcatContext != null) {
            ServletContext sc = tomcatContext.getServletContext();
            if (sc != null) {
                sc.setAttribute(AccessConstants.LOGBACK_STATUS_MANAGER_KEY, ctx.getStatusManager());
            }
        }
    }

    return INVOKE_NEXT;
}
 
開發者ID:goodees,項目名稱:goodees,代碼行數:25,代碼來源:CatalinaValve.java

示例9: getInstance

import javax.servlet.ServletContext; //導入方法依賴的package包/類
public static JspApplicationContextImpl getInstance(ServletContext context) {
	if (context == null) {
		throw new IllegalArgumentException("ServletContext was null");
	}
	JspApplicationContextImpl impl = (JspApplicationContextImpl) context
			.getAttribute(KEY);
	if (impl == null) {
		impl = new JspApplicationContextImpl();
		context.setAttribute(KEY, impl);
	}
	return impl;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:13,代碼來源:JspApplicationContextImpl.java

示例10: init

import javax.servlet.ServletContext; //導入方法依賴的package包/類
public void init(final ServletConfig config) {
    try {
        this.delegate.init(config);

    } catch (final Throwable t) {
        // let the service method know initialization failed.
        this.initSuccess = false;

        /*
         * no matter what went wrong, our role is to capture this error and
         * prevent it from blocking initialization of the servlet. logging
         * overkill so that our deployer will find a record of this problem
         * even if unfamiliar with Commons Logging and properly configuring
         * it.
         */

        final String message = "SafeDispatcherServlet: \n"
            + "The Spring DispatcherServlet we wrap threw on init.\n"
            + "But for our having caught this error, the servlet would not have initialized.";

        // logger it via Commons Logging
        LOGGER.error(message, t);

        // logger it to the ServletContext
        ServletContext context = config.getServletContext();
        context.log(message, t);

        /*
         * record the error so that the application has access to later
         * display a proper error message based on the exception.
         */
        context.setAttribute(CAUGHT_THROWABLE_KEY, t);

    }
}
 
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:36,代碼來源:SafeDispatcherServlet.java

示例11: contextInitialized

import javax.servlet.ServletContext; //導入方法依賴的package包/類
public void contextInitialized(ServletContext context) {
	try {
		initEurekaEnvironment();
		initEurekaServerContext();

		context.setAttribute(EurekaServerContext.class.getName(), this.serverContext);
	}
	catch (Throwable e) {
		log.error("Cannot bootstrap eureka server :", e);
		throw new RuntimeException("Cannot bootstrap eureka server :", e);
	}
}
 
開發者ID:dyc87112,項目名稱:didi-eureka-server,代碼行數:13,代碼來源:EurekaServerBootstrap.java

示例12: getApplicationContext

import javax.servlet.ServletContext; //導入方法依賴的package包/類
public synchronized static ConfigurableApplicationContext getApplicationContext(ServletContext servletContext, final String[] configLocations,
		final String[] classLocations) throws IOException
{
	final AbstractApplicationContext ctx = (AbstractApplicationContext)BaseApplicationContextHelper.getApplicationContext(configLocations, classLocations);
	DefaultListableBeanFactory dlbf = new DefaultListableBeanFactory(ctx.getBeanFactory());
	GenericWebApplicationContext gwac = new GenericWebApplicationContext(dlbf);
	CmisServiceFactory factory = (CmisServiceFactory)ctx.getBean("CMISServiceFactory");

	servletContext.setAttribute(GenericWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, gwac);
       servletContext.setAttribute(CmisRepositoryContextListener.SERVICES_FACTORY, factory);
	gwac.setServletContext(servletContext);
	gwac.refresh();

	return gwac;
}
 
開發者ID:Alfresco,項目名稱:alfresco-data-model,代碼行數:16,代碼來源:WebApplicationContextLoader.java

示例13: setServletContext

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void setServletContext(ServletContext servletContext) {
	for (Map.Entry<String, Object> entry : attributes.entrySet()) {
		String attributeName = entry.getKey();
		if (logger.isWarnEnabled()) {
			if (servletContext.getAttribute(attributeName) != null) {
				logger.warn("Replacing existing ServletContext attribute with name '" + attributeName + "'");
			}
		}
		servletContext.setAttribute(attributeName, entry.getValue());
		if (logger.isInfoEnabled()) {
			logger.info("Exported ServletContext attribute with name '" + attributeName + "'");
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:ServletContextAttributeExporter.java

示例14: init

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void init(ServletConfig config) throws ServletException {
    Info info = new Info()
            .title("Swagger Petstore")
            .description("This is a sample server Petstore server.  You can find out more about Swagger " +
                    "at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).  For this sample, " +
                    "you can use the api key `special-key` to test the authorization filters.")
            .termsOfService("http://swagger.io/terms/")
            .contact(new Contact()
                    .email("[email protected]"))
            .license(new License()
                    .name("Apache 2.0")
                    .url("http://www.apache.org/licenses/LICENSE-2.0.html"));

    ServletContext context = config.getServletContext();
    Swagger swagger = new Swagger()
            .info(info);
    swagger.securityDefinition("petstore_auth",
            new OAuth2Definition()
                    .implicit("http://localhost:8002/oauth/dialog")
                    .scope("email", "Access to your email address")
                    .scope("pets", "Access to your pets"));
    swagger.tag(new Tag()
            .name("pet")
            .description("Everything about your Pets")
            .externalDocs(new ExternalDocs("Find out more", "http://swagger.io")));
    swagger.tag(new Tag()
            .name("store")
            .description("Access to Petstore orders"));
    swagger.tag(new Tag()
            .name("user")
            .description("Operations about user")
            .externalDocs(new ExternalDocs("Find out more about our store", "http://swagger.io")));
    context.setAttribute("swagger", swagger);
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:36,代碼來源:Bootstrap.java

示例15: contextInitialized

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public final void contextInitialized(ServletContextEvent sce) {
  ServletContext context = sce.getServletContext();
  context.setAttribute(OryxResource.MODEL_MANAGER_KEY, getModelManager());
  context.setAttribute(OryxResource.INPUT_PRODUCER_KEY, new MockTopicProducer());
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:7,代碼來源:AbstractRDFServingTest.java


注:本文中的javax.servlet.ServletContext.setAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。