本文整理汇总了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, "/*");
}
示例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;
}
示例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, "/*");
}
示例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("/");
}
示例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);
}
示例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("/");
}
示例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));
}
示例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");
}
}
示例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
}
示例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());
}
示例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));
}
示例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));
}
示例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;
}
示例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("/");
}
示例15: onStartup
import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx)
throws ServletException {
ctx.addListener(new SCL());
}