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


Java ServletContext.addServlet方法代碼示例

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


在下文中一共展示了ServletContext.addServlet方法的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: onStartup

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void onStartup(ServletContext servletContext)
		throws ServletException {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.register(MyMvcConfig.class);
	ctx.setServletContext(servletContext); // ②

	Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
	servlet.addMapping("/");
	servlet.setLoadOnStartup(1);
}
 
開發者ID:longjiazuo,項目名稱:springMvc4.x-project,代碼行數:12,代碼來源:WebInitializer.java

示例3: contextInitialized

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

    ServletContext ctx = sce.getServletContext();

    ServletRegistration.Dynamic sd = ctx.addServlet("DynamicServlet",
            "com.creditease.monitorframework.fat.DynamicServlet");

    sd.addMapping("/DynamicServlet");
    sd.setInitParameter("test", "test");
    sd.setLoadOnStartup(1);
    sd.setAsyncSupported(false);

    FilterRegistration.Dynamic fd = ctx.addFilter("DynamicFilter",
            "com.creditease.monitorframework.fat.filters.DynamicFilter");

    fd.addMappingForUrlPatterns(null, true, "/DynamicServlet");
    fd.setInitParameter("test2", "test2");
    fd.setAsyncSupported(false);

    ctx.addListener("com.creditease.monitorframework.fat.listeners.TestServletInitListener");
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:23,代碼來源:DynamicServletInit.java

示例4: addDispatcherContext

import javax.servlet.ServletContext; //導入方法依賴的package包/類
private void addDispatcherContext(ServletContext container) {
	// Create the dispatcher servlet's Spring application context
	AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
	dispatcherContext.register(SpringDispatcherConfig.class);

	// Declare <servlet> and <servlet-mapping> for the DispatcherServlet
	ServletRegistration.Dynamic dispatcher = container.addServlet("ch03-servlet",
			new DispatcherServlet(dispatcherContext));
	dispatcher.addMapping("*.html");
	dispatcher.setLoadOnStartup(1);

	FilterRegistration.Dynamic corsFilter = container.addFilter("corsFilter", new CorsFilter());
	corsFilter.setInitParameter("cors.allowed.methods", "GET, POST, HEAD, OPTIONS, PUT, DELETE");
	corsFilter.addMappingForUrlPatterns(null, true, "/*");

	FilterRegistration.Dynamic filter = container.addFilter("hiddenmethodfilter", new HiddenHttpMethodFilter());
	filter.addMappingForServletNames(null, true, "/*");

	FilterRegistration.Dynamic multipartFilter = container.addFilter("multipartFilter", new MultipartFilter());
	multipartFilter.addMappingForUrlPatterns(null, true, "/*");

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

示例5: regiesterVIServlet

import javax.servlet.ServletContext; //導入方法依賴的package包/類
protected static final void regiesterVIServlet(ServletContext context,Logger logger){

        try {
            ServletRegistration.Dynamic asr = context.addServlet("VIApiServlet", VIApiServlet.class);

            if (asr != null) {
                asr.setLoadOnStartup(Integer.MAX_VALUE);
                asr.addMapping("/@in/api/*");
            } else {
                logger.warn("Servlet VIApiServlet already exists");
            }

            ServletRegistration ssr = context.addServlet("VIHttpServlet", StaticContentServlet.class);
            if (ssr != null) {
                ssr.addMapping("/@in/*");
            } else {
                logger.warn("Servlet VIHttpServlet already exists");
            }

        }catch (Throwable e){
            logger.error("VI register servlet failed",e);
        }
    }
 
開發者ID:ctripcorp,項目名稱:cornerstone,代碼行數:24,代碼來源:ServletRegister.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: onStartup

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

    // Register DispatcherServlet
    super.onStartup(servletContext);

    // Register H2 Admin console:
    ServletRegistration.Dynamic h2WebServlet = servletContext.addServlet("h2WebServlet",
            "org.h2.server.web.WebServlet");
    h2WebServlet.addMapping("/admin/h2/*");
    h2WebServlet.setInitParameter("webAllowOthers", "true");

}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:15,代碼來源:WebAppInitializer.java

示例8: registerServlets

import javax.servlet.ServletContext; //導入方法依賴的package包/類
private void registerServlets(ServletContext context){
	this.log.Info("Registrando Api");
	ServletRegistration.Dynamic rest_api =
            context.addServlet("api", new Rest());

	rest_api.addMapping("/api/*");
	rest_api.setAsyncSupported(true);
	// REGISTRAMOS LA CONSOLA
	this.log.Info("Registrando Api Console");
	ServletRegistration.Dynamic console_api =
            context.addServlet("console", new AdminApi());

	console_api.addMapping("/console/*");
	console_api.setAsyncSupported(true);
}
 
開發者ID:acalvoa,項目名稱:EARLGREY,代碼行數:16,代碼來源:Kernel.java

示例9: onStartup

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void onStartup(ServletContext servletContext)
		throws ServletException {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.register(MyMvcConfig.class);
	ctx.setServletContext(servletContext); // ②

	Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
	servlet.addMapping("/");
	servlet.setLoadOnStartup(1);
	servlet.setAsyncSupported(true);//①
}
 
開發者ID:longjiazuo,項目名稱:springMvc4.x-project,代碼行數:13,代碼來源:WebInitializer.java

示例10: initH2Console

import javax.servlet.ServletContext; //導入方法依賴的package包/類
/**
 * Initializes H2 console.
 */
private void initH2Console(ServletContext servletContext) {
    log.debug("Initialize H2 console");
    ServletRegistration.Dynamic h2ConsoleServlet = servletContext.addServlet("H2Console", new org.h2.server.web.WebServlet());
    h2ConsoleServlet.addMapping("/h2-console/*");
    h2ConsoleServlet.setInitParameter("-properties", "src/main/resources/");
    h2ConsoleServlet.setLoadOnStartup(1);
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:11,代碼來源:WebConfigurer.java

示例11: onStartup

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx)
        throws ServletException {
    // Register and map servlet
    s = new Bug51376Servlet();
    ServletRegistration.Dynamic sr = ctx.addServlet("bug51376", s);
    sr.addMapping("/bug51376");
    if (loadOnStartUp) {
        sr.setLoadOnStartup(1);
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:12,代碼來源:TestStandardContext.java

示例12: onStartup

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx)
        throws ServletException {
    Servlet s;

    if (createServlet) {
        s = ctx.createServlet(servlet.getClass());
    } else {
        s = servlet;
    }
    ServletRegistration.Dynamic r = ctx.addServlet("servlet", s);
    r.addMapping("/");
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:14,代碼來源:TestStandardWrapper.java

示例13: addDispatcherContext

import javax.servlet.ServletContext; //導入方法依賴的package包/類
private void addDispatcherContext(ServletContext container) {
  // Create the dispatcher servlet's Spring application context
  AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
  dispatcherContext.register(SpringDispatcherConfig.class); 
	 
  // Declare  <servlet> and <servlet-mapping> for the DispatcherServlet
  ServletRegistration.Dynamic dispatcher = container.addServlet("ch02-servlet", 
  		new DispatcherServlet(dispatcherContext));
  dispatcher.addMapping("*.html");
  dispatcher.setLoadOnStartup(1);
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:12,代碼來源:SpringWebInitializer.java

示例14: useDispatcherContext

import javax.servlet.ServletContext; //導入方法依賴的package包/類
private void useDispatcherContext(ServletContext container) {
  // Create the dispatcher servlet's Spring application context
  AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
  dispatcherContext.register(SpringDispatcherConfig.class); // <-- Use DispatcherConfig.java
	 
  // Define mapping between <servlet> and <servlet-mapping>
  ServletRegistration.Dynamic dispatcher = container.addServlet("spring-dispatcher", new DispatcherServlet(
      dispatcherContext));
  dispatcher.addMapping("/");
  dispatcher.setLoadOnStartup(1);
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:12,代碼來源:SpringWebInitializer.java

示例15: addDispatcherContext

import javax.servlet.ServletContext; //導入方法依賴的package包/類
private void addDispatcherContext(ServletContext container) {
  // Create the dispatcher servlet's Spring application context
  AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
  dispatcherContext.register(SpringDispatcherConfig.class); 
	 
  // Declare  <servlet> and <servlet-mapping> for the DispatcherServlet
  ServletRegistration.Dynamic dispatcher = container.addServlet("ch07-servlet", 
  		new DispatcherServlet(dispatcherContext));
  dispatcher.addMapping("/");
  dispatcher.setLoadOnStartup(1);
  
 
     
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:15,代碼來源:SpringWebinitializer.java


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