List of usage examples for javax.servlet ServletContext addFilter
public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass);
From source file:net.przemkovv.sphinx.config.ApplicationInitializer.java
public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationConfig.class, JpaConfig.class); // rootContext.refresh(); rootContext.setDisplayName("Sphinx Web Application"); servletContext.addListener(new ContextLoaderListener(rootContext)); // servletContext.addListener(new HttpSessionEventPublisher()); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(WebMvcConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("Spring MVC Servlet", new DispatcherServlet(dispatcherContext)); dispatcher.addMapping("/app/"); dispatcher.setLoadOnStartup(1);/*from w w w . j a v a 2s. c om*/ // servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")) // .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); servletContext.addFilter("UrlRewriteFilter", new UrlRewriteFilter()).addMappingForUrlPatterns(null, true, "/*"); servletContext.addFilter("HttpMethodFilter", new HiddenHttpMethodFilter()).addMappingForUrlPatterns(null, true, "/*"); servletContext.addFilter("HttpPutFormContentFilter", new HttpPutFormContentFilter()) .addMappingForUrlPatterns(null, true, "/*"); FilterRegistration.Dynamic charsetFilter = servletContext.addFilter("charsetFilter", new CharacterEncodingFilter()); charsetFilter.setInitParameter("encoding", "UTF-8"); charsetFilter.setInitParameter("forceEncoding", "true"); charsetFilter.addMappingForUrlPatterns(null, true, "/*"); FilterRegistration.Dynamic dustCompilingFilter = servletContext.addFilter("dustCompilingFilter", new DustCompilingFilter()); dustCompilingFilter.setInitParameter("templateNameRegex", "/template/(.*).dust.js$"); dustCompilingFilter.addMappingForUrlPatterns(null, true, "/*"); }
From source file:com.haulmont.cuba.web.sys.singleapp.SingleAppWebContextLoader.java
protected void registerRestApiServlet(ServletContext servletContext) { CubaRestApiServlet cubaRestApiServlet = new SingleAppRestApiServlet(dependencyJars); try {/*from w ww.j a va 2 s . c o m*/ cubaRestApiServlet.init(new CubaServletConfig("rest_api", servletContext)); } catch (ServletException e) { throw new RuntimeException("An error occurred while initializing dispatcher servlet", e); } ServletRegistration.Dynamic cubaRestApiServletReg = servletContext.addServlet("rest_api", cubaRestApiServlet); cubaRestApiServletReg.setLoadOnStartup(2); cubaRestApiServletReg.addMapping("/rest/*"); DelegatingFilterProxy restSpringSecurityFilterChain = new DelegatingFilterProxy(); restSpringSecurityFilterChain .setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.rest_api"); restSpringSecurityFilterChain.setTargetBeanName("springSecurityFilterChain"); FilterRegistration.Dynamic restSpringSecurityFilterChainReg = servletContext .addFilter("restSpringSecurityFilterChain", restSpringSecurityFilterChain); restSpringSecurityFilterChainReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/rest/*"); }
From source file:be.wolkmaan.klimtoren.web.config.WebAppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Create the root appcontext AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootConfig.class); rootContext.register(PersistenceConfig.class); // Manage the lifecycle of the root appcontext servletContext.addListener(new ContextLoaderListener(rootContext)); servletContext.setInitParameter("defaultHtmlEscape", "true"); this.zkLoaderServlet(servletContext); // now the config for the Dispatcher servlet AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); mvcContext.register(WebMvcConfig.class); // Filters//from w w w. j a v a 2 s .c o m // http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/filter/package-summary.html // Enables support for DELETE and PUT request methods with web browser // clients // http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/filter/HiddenHttpMethodFilter.html FilterRegistration.Dynamic fr = servletContext.addFilter("hiddenHttpMethodFilter", new HiddenHttpMethodFilter()); fr.addMappingForUrlPatterns(null, true, "/*"); fr = servletContext.addFilter("encodingFilter", new CharacterEncodingFilter()); fr.setInitParameter("encoding", "UTF-8"); fr.setInitParameter("forceEncoding", "true"); fr.addMappingForUrlPatterns(null, true, "/*"); // The main Spring MVC servlet. ServletRegistration.Dynamic appServlet = servletContext.addServlet("appServlet", new DispatcherServlet(mvcContext)); appServlet.setLoadOnStartup(2); Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { for (String s : mappingConflicts) { logger.error("Mapping conflict: " + s); } throw new IllegalStateException("'appServlet' cannot be mapped to '/' under Tomcat versions <= 7.0.14"); } HttpSessionListener zkCleanUp = new HttpSessionListener(); servletContext.addListener(zkCleanUp); this.logbackServlet(servletContext); this.zkUpdateServlet(servletContext); }
From source file:com.zxy.commons.hystrix.web.HystrixInitializer.java
/** * {@inheritDoc}//from w w w. ja va 2 s .c o m */ public void onStartup(ServletContext container) throws ServletException { // WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(container); Properties properties = load(); String enabled = properties.getProperty(HystrixProperties.HYSTRIX_ENABLED); String streamEnabled = properties.getProperty(HystrixProperties.HYSTRIX_STREAM_ENABLED); if ((StringUtils.isBlank(enabled) || "true".equalsIgnoreCase(enabled)) && (StringUtils.isBlank(streamEnabled) || "true".equalsIgnoreCase(streamEnabled))) { // AnnotationConfigWebApplicationContext ctx = new // AnnotationConfigWebApplicationContext(); // ctx.register(AppConfig.class); // ctx.setServletContext(container); // ServletRegistration.Dynamic servlet = // container.addServlet("dispatcher", new DispatcherServlet(ctx)); // WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(container); // servlet.setLoadOnStartup(1); // servlet.addMapping("/"); FilterRegistration.Dynamic hystrixRequestContextServletFilter = container .addFilter("HystrixRequestContextServletFilter", new HystrixRequestContextServletFilter()); hystrixRequestContextServletFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); FilterRegistration.Dynamic hystrixRequestLogViaResponseHeaderServletFilter = container.addFilter( "HystrixRequestLogViaResponseHeaderServletFilter", new HystrixRequestLogViaResponseHeaderServletFilter()); hystrixRequestLogViaResponseHeaderServletFilter .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); ServletRegistration.Dynamic hystrixMetricsStreamServlet = container .addServlet("HystrixMetricsStreamServlet", new HystrixMetricsStreamServlet()); hystrixMetricsStreamServlet.addMapping("/hystrix.stream"); // ServletRegistration.Dynamic proxyStreamServlet = // container.addServlet("ProxyStreamServlet", new // ProxyStreamServlet()); // proxyStreamServlet.addMapping("/proxy.stream"); } }
From source file:com.techtrip.dynbl.context.config.WebAppinitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Setup Context to Accept Annotated Classes on Input (including plain Spring {@code @Component} // Stereotypes in addition to JSR-330 Compliant Classes using {@code javax.inject} AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); //context.setConfigLocation(APP_CONFIG_LOCATION); context.setConfigLocation(APP_CONFIG_LOCATION); /* //from w w w. ja va 2 s . co m * Add a Spring Security Filter using the JEE6 Filter Registration Filter Method from {@code FilterRegistration) that allows filters to be registered * and configured with the specified context */ /* FilterRegistration.Dynamic securityFilter = servletContext.addFilter(ProjectKeyValConsts.SECURITY_FILTER.getKey(), new DelegatingFilterProxy(ProjectKeyValConsts.SECURITY_FILTER.getValue())); securityFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ProjectConsts.BASE_URL_MAPPING_PATTERN.getValue()); // where the filter will be applied */ // Add a Character Encoding Filter that specifies an encoding for mapped requests FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter()); characterEncodingFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ROOT_CONTEXT); // where the filter will be applied characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", Boolean.TRUE.toString()); characterEncodingFilter.setAsyncSupported(true); servletContext.addListener(new ContextLoaderListener(context)); servletContext.setInitParameter("defaultHtmlEscape", Boolean.TRUE.toString()); DispatcherServlet servlet = new DispatcherServlet(); // no explicit configuration reference here: everything is configured in the root container for simplicity servlet.setContextConfigLocation(""); /* TMT From JEE 6 API Docs: * Registers the given servlet instance with this ServletContext under the given servletName. * The registered servlet may be further configured via the returned ServletRegistration object. */ ServletRegistration.Dynamic appServlet = servletContext.addServlet(APP_SERVLET, servlet); appServlet.setLoadOnStartup(1); appServlet.setAsyncSupported(true); Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { throw new IllegalStateException(String.format( "The servlet named '%s' cannot be mapped to '/' under Tomcat versions <= 7.0.14", APP_SERVLET)); } // TMT servletContext.addListener(new Log4jConfigListener()); System.out.println("Application inplemented on Spring Version: " + SpringVersion.getVersion()); }
From source file:com.haulmont.cuba.web.sys.singleapp.SingleAppWebContextLoader.java
protected void registerIdpServlet(ServletContext servletContext) { String serviceProvidersUrls = AppContext.getProperty(IDP_SERVICE_PROVIDERS_URLS); if (StringUtils.isEmpty(serviceProvidersUrls)) { log.debug("No service providers were found. IDP Servlet will not be started"); return;//from w w w.j a va 2 s . c o m } CubaIdpServlet idpServlet = new SingleAppIdpServlet(dependencyJars); try { idpServlet.init(new CubaServletConfig("idp", servletContext)); } catch (ServletException e) { throw new RuntimeException("An error occurred while initializing idp servlet", e); } ServletRegistration.Dynamic idpServletRegistration = servletContext.addServlet("idp", idpServlet); idpServletRegistration.setLoadOnStartup(4); idpServletRegistration.addMapping("/idp/*"); DelegatingFilterProxy idpSpringSecurityFilterChain = new DelegatingFilterProxy(); idpSpringSecurityFilterChain .setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.idp"); idpSpringSecurityFilterChain.setTargetBeanName("springSecurityFilterChain"); FilterRegistration.Dynamic idpSpringSecurityFilterChainReg = servletContext .addFilter("idpSpringSecurityFilterChain", idpSpringSecurityFilterChain); idpSpringSecurityFilterChainReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/idp/*"); }
From source file:com.consol.citrus.simulator.WebAppInitializer.java
public void onStartup(ServletContext servletContext) throws ServletException { XmlWebApplicationContext appContext = new XmlWebApplicationContext(); appContext.setConfigLocation("/WEB-INF/citrus-servlet-context.xml"); ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("citrus", new MessageDispatcherServlet()); dispatcherServlet.setLoadOnStartup(1); dispatcherServlet.addMapping("/simulator"); dispatcherServlet.addMapping("/simulator/*"); dispatcherServlet.setInitParameter("contextConfigLocation", ""); ServletRegistration.Dynamic statusServlet = servletContext.addServlet("status", new SimulatorStatusServlet()); statusServlet.setLoadOnStartup(1000); statusServlet.addMapping("/status"); statusServlet.addMapping("/status/*"); ServletRegistration.Dynamic runServlet = servletContext.addServlet("run", new SimulatorRunServlet()); runServlet.setLoadOnStartup(1000);//from w ww.j a v a 2 s. c o m runServlet.addMapping("/run"); runServlet.addMapping("/run/*"); ServletRegistration.Dynamic resourceServlet = servletContext.addServlet("resource", new StaticResourceServlet()); resourceServlet.setLoadOnStartup(1000); resourceServlet.addMapping("/info"); resourceServlet.addMapping("/info/*"); servletContext.addListener(new ContextLoaderListener(appContext)); CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding(System.getProperty("file.encoding", "UTF-8")); encodingFilter.setForceEncoding(true); FilterRegistration.Dynamic filter = servletContext.addFilter("encoding-filter", encodingFilter); filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); }
From source file:cz.muni.fi.editor.webapp.config.init.EditorApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { String bootLogo = " __ __ _ _ _ _ _ _ \n" + " | \\/ | | | | | | | | (_) | \n" + " | \\ / | ___| |_ __ _ __| | __ _| |_ __ _ ___ __| |_| |_ ___ _ __ \n" + " | |\\/| |/ _ \\ __/ _` |/ _` |/ _` | __/ _` | / _ \\/ _` | | __/ _ \\| '__|\n" + " | | | | __/ || (_| | (_| | (_| | || (_| | | __/ (_| | | || (_) | | \n" + " |_| |_|\\___|\\__\\__,_|\\__,_|\\__,_|\\__\\__,_| \\___|\\__,_|_|\\__\\___/|_| \n" + " \n" + " "; System.out.println(ANSI_YELLOW + bootLogo + ANSI_RESET); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.getEnvironment().setActiveProfiles("production"); rootContext.register(WebAppConfiguration.class, SecurityConfig.class); servletContext.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(MvcConfiguration.class, WebSocketSecurityConfiguration.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1);//from w w w. java 2 s. c o m dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); servletContext.addFilter("encodingFilter", new CharacterEncodingFilter("UTF-8", true)) .addMappingForUrlPatterns(null, false, "/*"); servletContext.addFilter("httpMethodFilter", new HiddenHttpMethodFilter()).addMappingForUrlPatterns(null, true, "/*"); }
From source file:fr.univlorraine.mondossierweb.Initializer.java
/** * @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext) *//*from w w w .j av a 2 s . co m*/ @Override public void onStartup(ServletContext servletContext) throws ServletException { addContextParametersToSystemProperties(servletContext); /* Configure les sessions */ Set<SessionTrackingMode> sessionTrackingModes = new HashSet<SessionTrackingMode>(); sessionTrackingModes.add(SessionTrackingMode.COOKIE); servletContext.setSessionTrackingModes(sessionTrackingModes); servletContext.addListener(new HttpSessionListener() { @Override public void sessionCreated(HttpSessionEvent httpSessionEvent) { // sans nouvelle requte, on garde la session active 4 minutes httpSessionEvent.getSession().setMaxInactiveInterval(240); } @Override public void sessionDestroyed(HttpSessionEvent httpSessionEvent) { } }); /* Gestion des sessions dans Atmosphere (Push Vaadin) */ servletContext.addListener(SessionSupport.class); /* Configure Spring */ AnnotationConfigWebApplicationContext springContext = new AnnotationConfigWebApplicationContext(); if (!Boolean.valueOf(servletContext.getInitParameter(Constants.SERVLET_PARAMETER_PRODUCTION_MODE))) { springContext.getEnvironment().setActiveProfiles(DEBUG_PROFILE); } springContext.register(SpringConfig.class); servletContext.addListener(new ContextLoaderListener(springContext)); servletContext.addListener(new RequestContextListener()); /* Filtre Spring Security */ FilterRegistration.Dynamic springSecurityFilterChain = servletContext.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class); springSecurityFilterChain.addMappingForUrlPatterns(null, false, "/*"); /* Filtre passant l'utilisateur courant Logback */ FilterRegistration.Dynamic userMdcServletFilter = servletContext.addFilter("userMdcServletFilter", UserMdcServletFilter.class); userMdcServletFilter.addMappingForUrlPatterns(null, false, "/*"); /* Filtre Spring Mobile permettant de dtecter le device */ FilterRegistration.Dynamic springMobileServletFilter = servletContext .addFilter("deviceResolverRequestFilter", DeviceResolverRequestFilter.class); springMobileServletFilter.addMappingForUrlPatterns(null, false, "/*"); /* Servlet Spring-Vaadin */ //ServletRegistration.Dynamic springVaadinServlet = servletContext.addServlet("springVaadin", JMeterServlet.class); //ServletRegistration.Dynamic springVaadinServlet = servletContext.addServlet("springVaadin", SpringVaadinServlet.class); ServletRegistration.Dynamic springVaadinServlet = servletContext.addServlet("springVaadin", fr.univlorraine.mondossierweb.utils.MdwSpringVaadinServlet.class); springVaadinServlet.setLoadOnStartup(1); springVaadinServlet.addMapping("/*"); /* Dfini le bean UI */ //springVaadinServlet.setInitParameter(Constants.SERVLET_PARAMETER_UI_PROVIDER, "fr.univlorraine.mondossierweb.MdwUIProvider"); /* Utilise les messages Spring pour les messages d'erreur Vaadin (cf. http://vaadin.xpoft.ru/#system_messages) */ springVaadinServlet.setInitParameter("systemMessagesBeanName", "DEFAULT"); /* Dfini la frquence du heartbeat en secondes (cf. https://vaadin.com/book/vaadin7/-/page/application.lifecycle.html#application.lifecycle.ui-expiration) */ springVaadinServlet.setInitParameter(Constants.SERVLET_PARAMETER_HEARTBEAT_INTERVAL, String.valueOf(30)); /* Configure le Push */ springVaadinServlet.setInitParameter(Constants.SERVLET_PARAMETER_PUSH_MODE, Boolean.valueOf(servletContext.getInitParameter("enablePush")) ? PushMode.AUTOMATIC.name() : PushMode.DISABLED.name()); /* Active le support des servlet 3 et des requtes asynchrones (cf. https://vaadin.com/wiki/-/wiki/Main/Working+around+push+issues) */ springVaadinServlet.setInitParameter(ApplicationConfig.WEBSOCKET_SUPPORT_SERVLET3, String.valueOf(true)); /* Active le support des requtes asynchrones */ springVaadinServlet.setAsyncSupported(true); /* Ajoute l'interceptor Atmosphere permettant de restaurer le SecurityContext dans le SecurityContextHolder (cf. https://groups.google.com/forum/#!msg/atmosphere-framework/8yyOQALZEP8/ZCf4BHRgh_EJ) */ springVaadinServlet.setInitParameter(ApplicationConfig.ATMOSPHERE_INTERCEPTORS, RecoverSecurityContextAtmosphereInterceptor.class.getName()); /* Spring-Vaadin Touchkit Servlet */ ServletRegistration.Dynamic springTouchkitVaadinServlet = servletContext.addServlet("springTouchkitVaadin", MDWTouchkitServlet.class); //springTouchkitVaadinServlet.setLoadOnStartup(1); springTouchkitVaadinServlet.addMapping("/m/*"); /* Dfini le bean UI */ //springTouchkitVaadinServlet.setInitParameter(Constants.SERVLET_PARAMETER_UI_PROVIDER, "fr.univlorraine.mondossierweb.MdwTouchkitUIProvider"); /* Utilise les messages Spring pour les messages d'erreur Vaadin (cf. http://vaadin.xpoft.ru/#system_messages) */ springTouchkitVaadinServlet.setInitParameter("systemMessagesBeanName", "DEFAULT"); springTouchkitVaadinServlet.setInitParameter(Constants.PARAMETER_WIDGETSET, "fr.univlorraine.mondossierweb.AppWidgetset"); /* Configure le Push */ springTouchkitVaadinServlet.setInitParameter(Constants.SERVLET_PARAMETER_PUSH_MODE, PushMode.DISABLED.name()); /* Active le support des servlet 3 et des requtes asynchrones (cf. https://vaadin.com/wiki/-/wiki/Main/Working+around+push+issues) */ springTouchkitVaadinServlet.setInitParameter(ApplicationConfig.WEBSOCKET_SUPPORT_SERVLET3, String.valueOf(true)); /* Active le support des requtes asynchrones */ springTouchkitVaadinServlet.setAsyncSupported(true); /* Ajoute l'interceptor Atmosphere permettant de restaurer le SecurityContext dans le SecurityContextHolder (cf. https://groups.google.com/forum/#!msg/atmosphere-framework/8yyOQALZEP8/ZCf4BHRgh_EJ) */ springTouchkitVaadinServlet.setInitParameter(ApplicationConfig.ATMOSPHERE_INTERCEPTORS, RecoverSecurityContextAtmosphereInterceptor.class.getName()); }
From source file:org.smigo.config.WebAppInitializer.java
@Override protected void beforeSpringSecurityFilterChain(ServletContext servletContext) { super.beforeSpringSecurityFilterChain(servletContext); log.info("Starting servlet context"); log.info("contextName: " + servletContext.getServletContextName()); log.info("contextPath:" + servletContext.getContextPath()); log.info("effectiveMajorVersion:" + servletContext.getEffectiveMajorVersion()); log.info("effectiveMinorVersion:" + servletContext.getEffectiveMinorVersion()); log.info("majorVersion:" + servletContext.getMajorVersion()); log.info("minorVersion:" + servletContext.getMinorVersion()); log.info("serverInfo:" + servletContext.getServerInfo()); // ", virtualServerName:" + servletContext.getVirtualServerName() + log.info("toString:" + servletContext.toString()); for (Enumeration<String> e = servletContext.getAttributeNames(); e.hasMoreElements();) { log.info("Attribute:" + e.nextElement()); }//from ww w . j a v a 2s. c o m for (Map.Entry<String, String> env : System.getenv().entrySet()) { log.info("System env:" + env.toString()); } for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) { log.info("System prop:" + prop.toString()); } final String profile = System.getProperty("smigoProfile", EnvironmentProfile.PRODUCTION); log.info("Starting with profile " + profile); WebApplicationContext context = new AnnotationConfigWebApplicationContext() { { register(WebConfiguration.class); setDisplayName("SomeRandomName"); getEnvironment().setActiveProfiles(profile); } }; FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("CharacterEncodingFilter", new CharacterEncodingFilter()); characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", "true"); characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*"); servletContext.addListener(new RequestContextListener()); servletContext.addListener(new ContextLoaderListener(context)); //http://stackoverflow.com/questions/4811877/share-session-data-between-2-subdomains // servletContext.getSessionCookieConfig().setDomain(getDomain()); DispatcherServlet dispatcherServlet = new DispatcherServlet(context); dispatcherServlet.setThrowExceptionIfNoHandlerFound(false); servletContext.addServlet("dispatcher", dispatcherServlet).addMapping("/"); }