当前位置: 首页>>代码示例>>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;未经允许,请勿转载。