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


Java ServletContext.addListener方法代碼示例

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


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

示例1: onStartup

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	//register config classes
	AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
	rootContext.register(WebMvcConfig.class);
	rootContext.register(JPAConfig.class);
	rootContext.register(WebSecurityConfig.class);
	rootContext.register(ServiceConfig.class);
	//set session timeout
	servletContext.addListener(new SessionListener(maxInactiveInterval));
	//set dispatcher servlet and mapping
	ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
			new DispatcherServlet(rootContext));
	dispatcher.addMapping("/");
	dispatcher.setLoadOnStartup(1);
	
	//register filters
	FilterRegistration.Dynamic filterRegistration = servletContext.addFilter("endcodingFilter", new CharacterEncodingFilter());
	filterRegistration.setInitParameter("encoding", "UTF-8");
	filterRegistration.setInitParameter("forceEncoding", "true");
	//make sure encodingFilter is matched first
	filterRegistration.addMappingForUrlPatterns(null, false, "/*");
	//disable appending jsessionid to the URL
	filterRegistration = servletContext.addFilter("disableUrlSessionFilter", new DisableUrlSessionFilter());
	filterRegistration.addMappingForUrlPatterns(null, true, "/*");
}
 
開發者ID:Azanx,項目名稱:Smart-Shopping,代碼行數:27,代碼來源:WebMvcInitialiser.java

示例2: 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

示例3: onStartup

import javax.servlet.ServletContext; //導入方法依賴的package包/類
/**
 * Configure the given {@link ServletContext} with any servlets, filters, listeners
 * context-params and attributes necessary for initializing this web application. See examples
 * {@linkplain WebApplicationInitializer above}.
 *
 * @param servletContext the {@code ServletContext} to initialize
 * @throws ServletException if any call against the given {@code ServletContext} throws a {@code ServletException}
 */
public void onStartup(ServletContext servletContext) throws ServletException {
	// Spring Context Bootstrapping
	AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext();
	rootAppContext.register(AutoPivotConfig.class);
	servletContext.addListener(new ContextLoaderListener(rootAppContext));

	// Set the session cookie name. Must be done when there are several servers (AP,
	// Content server, ActiveMonitor) with the same URL but running on different ports.
	// Cookies ignore the port (See RFC 6265).
	CookieUtil.configure(servletContext.getSessionCookieConfig(), CookieUtil.COOKIE_NAME);

	// The main servlet/the central dispatcher
	final DispatcherServlet servlet = new DispatcherServlet(rootAppContext);
	servlet.setDispatchOptionsRequest(true);
	Dynamic dispatcher = servletContext.addServlet("springDispatcherServlet", servlet);
	dispatcher.addMapping("/*");
	dispatcher.setLoadOnStartup(1);

	// Spring Security Filter
	final FilterRegistration.Dynamic springSecurity = servletContext.addFilter(SPRING_SECURITY_FILTER_CHAIN, new DelegatingFilterProxy());
	springSecurity.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

}
 
開發者ID:activeviam,項目名稱:autopivot,代碼行數:32,代碼來源:AutoPivotWebAppInitializer.java

示例4: onStartup

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void onStartup(ServletContext container) {
	// Create the 'root' Spring application context
	AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
	rootContext.register(AppConfig.class);

	// Manage the lifecycle of the root application context
	container.addListener(new ContextLoaderListener(rootContext));

	// Create the dispatcher servlet's Spring application context
	AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();

	// Register and map the dispatcher servlet
	ServletRegistration.Dynamic dispatcher = container
			.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/");
}
 
開發者ID:auth0-blog,項目名稱:embedded-spring-5,代碼行數:19,代碼來源:AppConfig.java

示例5: onStartup

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	WebApplicationContext context = getContext();
	servletContext.addListener(new ContextLoaderListener(context));
	servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter("UTF-8"));

	DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
	dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);

	ServletRegistration.Dynamic dispatcher = servletContext.addServlet("Dispatcher", dispatcherServlet);
	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/*");

	CXFServlet cxf = new CXFServlet();
	BusFactory.setDefaultBus(cxf.getBus());
	ServletRegistration.Dynamic cxfServlet = servletContext.addServlet("CXFServlet", cxf);
	cxfServlet.setLoadOnStartup(1);
	cxfServlet.addMapping("/services/*");

	servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")).addMappingForUrlPatterns(null, false,
			"/*");

	servletContext.getSessionCookieConfig().setSecure(cookieSecure);
}
 
開發者ID:esig,項目名稱:dss-demonstrations,代碼行數:25,代碼來源:AppInitializer.java

示例6: onStartup

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    //On charge le contexte de l'app
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setDisplayName("scrumtracker");
    rootContext.register(ApplicationContext.class);

    //Context loader listener
    servletContext.addListener(new ContextLoaderListener(rootContext));

    //Dispatcher servlet
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
}
 
開發者ID:scrumtracker,項目名稱:scrumtracker2017,代碼行數:17,代碼來源:ApplicationInitializer.java

示例7: addRootContext

import javax.servlet.ServletContext; //導入方法依賴的package包/類
private void addRootContext(ServletContext container) {
  // Create the application context
  AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
  rootContext.register(SpringContextConfig.class); 
	 
  // Register application context with ContextLoaderListener
  container.addListener(new ContextLoaderListener(rootContext));
   
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:10,代碼來源:SpringWebinitializer.java

示例8: registerContextLoaderListener

import javax.servlet.ServletContext; //導入方法依賴的package包/類
/**
 * Register a {@link ContextLoaderListener} against the given servlet context. The
 * {@code ContextLoaderListener} is initialized with the application context returned
 * from the {@link #createRootApplicationContext()} template method.
 * @param servletContext the servlet context to register the listener against
 */
protected void registerContextLoaderListener(ServletContext servletContext) {
	WebApplicationContext rootAppContext = createRootApplicationContext();
	if (rootAppContext != null) {
		servletContext.addListener(new ContextLoaderListener(rootAppContext));
	}
	else {
		logger.debug("No ContextLoaderListener registered, as " +
				"createRootApplicationContext() did not return an application context");
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:AbstractContextLoaderInitializer.java

示例9: addRootContext

import javax.servlet.ServletContext; //導入方法依賴的package包/類
private void addRootContext(ServletContext container) {
  // Create the application context
  AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
  rootContext.register(SpringContextConfig.class); 
	 
  // Register application context with ContextLoaderListener
  container.addListener(new ContextLoaderListener(rootContext));
 container.setInitParameter("contextConfigLocation", "org.packt.web.reactor.security.config");
 container.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE)); // if URL, enable sessionManagement URL rewriting   
	 
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:12,代碼來源:SpringWebinitializer.java

示例10: addRootContext

import javax.servlet.ServletContext; //導入方法依賴的package包/類
private void addRootContext(ServletContext container) {
	// Create the application context
	AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
	rootContext.register(SpringContextConfig.class);

	// Register application context with ContextLoaderListener
	container.addListener(new ContextLoaderListener(rootContext));
	//container.addListener(new RequestContextListener());

}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:11,代碼來源:SpringWebInitializer.java

示例11: addRootContext

import javax.servlet.ServletContext; //導入方法依賴的package包/類
private void addRootContext(ServletContext container) {
  // Create the application context
  AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
  rootContext.register(SpringContextConfig.class); 
	 
  // Register application context with ContextLoaderListener
  container.addListener(new ContextLoaderListener(rootContext));
  
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:10,代碼來源:SpringWebinitializer.java

示例12: addRootContext

import javax.servlet.ServletContext; //導入方法依賴的package包/類
private void addRootContext(ServletContext container) {
  // Create the application context
  AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
  rootContext.register(SpringContextConfig.class); 
	 
  // Register application context with ContextLoaderListener
  container.addListener(new ContextLoaderListener(rootContext));
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:9,代碼來源:SpringWebInitializer.java

示例13: 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:how2j,項目名稱:lazycat,代碼行數:16,代碼來源:WsSci.java

示例14: onStartup

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void onStartup(ServletContext container) {

    WebApplicationContext rootContext = getContext();
    container.addListener(new ContextLoaderListener(rootContext));

    AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
    dispatcherContext.register(DispatcherConfig.class);

    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");

}
 
開發者ID:ArturWisniewski,項目名稱:ToDoApp-Spring,代碼行數:15,代碼來源:Application.java

示例15: onStartup

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx)
        throws ServletException {
    ctx.addListener(new SCL());
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:6,代碼來源:TestListener.java


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