当前位置: 首页>>代码示例>>Java>>正文


Java ServletRegistration.Dynamic方法代码示例

本文整理汇总了Java中javax.servlet.ServletRegistration.Dynamic方法的典型用法代码示例。如果您正苦于以下问题:Java ServletRegistration.Dynamic方法的具体用法?Java ServletRegistration.Dynamic怎么用?Java ServletRegistration.Dynamic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.ServletRegistration的用法示例。


在下文中一共展示了ServletRegistration.Dynamic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onStartup

import javax.servlet.ServletRegistration; //导入方法依赖的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: initMetrics

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
/**
 * Initializes Metrics.
 */
private void initMetrics(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    log.debug("Initializing Metrics registries");
    servletContext.setAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE,
        metricRegistry);
    servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY,
        metricRegistry);

    log.debug("Registering Metrics Filter");
    FilterRegistration.Dynamic metricsFilter = servletContext.addFilter("webappMetricsFilter",
        new InstrumentedFilter());

    metricsFilter.addMappingForUrlPatterns(disps, true, "/*");
    metricsFilter.setAsyncSupported(true);

    log.debug("Registering Metrics Servlet");
    ServletRegistration.Dynamic metricsAdminServlet =
        servletContext.addServlet("metricsServlet", new MetricsServlet());

    metricsAdminServlet.addMapping("/management/metrics/*");
    metricsAdminServlet.setAsyncSupported(true);
    metricsAdminServlet.setLoadOnStartup(2);
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:26,代码来源:WebConfigurer.java

示例3: addDispatcherContext

import javax.servlet.ServletRegistration; //导入方法依赖的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

示例4: addServlet

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
@Override
public ServletRegistration.Dynamic addServlet(final String servletName, final String className) {
    ensureNotProgramaticListener();
    ensureNotInitialized();
    try {
        if (deploymentInfo.getServlets().containsKey(servletName)) {
            return null;
        }
        ServletInfo servlet = new ServletInfo(servletName, (Class<? extends Servlet>) deploymentInfo.getClassLoader().loadClass(className));
        readServletAnnotations(servlet);
        deploymentInfo.addServlet(servlet);
        ServletHandler handler = deployment.getServlets().addServlet(servlet);
        return new ServletRegistrationImpl(servlet, handler.getManagedServlet(), deployment);
    } catch (ClassNotFoundException e) {
        throw UndertowServletMessages.MESSAGES.cannotLoadClass(className, e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:ServletContextImpl.java

示例5: onStartup

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
public void onStartup(ServletContext container) throws ServletException {

        AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
        ctx.register(AppConfig.class);
        ctx.setServletContext(container);

        ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
        servlet.setLoadOnStartup(1);
        servlet.addMapping("/");
    }
 
开发者ID:xSzymo,项目名称:Spring-web-shop-project,代码行数:11,代码来源:AppInitializer.java

示例6: onStartup

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx)
        throws ServletException {
    // Register and map servlet
    Servlet s = new Bug50015Servlet();
    ServletRegistration.Dynamic sr = ctx.addServlet("bug50015", s);
    sr.addMapping("/bug50015");

    // Limit access to users in the Tomcat role
    HttpConstraintElement hce = new HttpConstraintElement(
            TransportGuarantee.NONE, "tomcat");
    ServletSecurityElement sse = new ServletSecurityElement(hce);
    sr.setServletSecurity(sse);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:15,代码来源:TestStandardContext.java

示例7: onStartup

import javax.servlet.ServletRegistration; //导入方法依赖的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: onStartup

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
public void onStartup(ServletContext container) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(HelloWorldConfiguration.class);
    ctx.setServletContext(container);

    ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));

    servlet.setLoadOnStartup(1);
    servlet.addMapping("/");
}
 
开发者ID:garyhu1,项目名称:spring_mvc_demo,代码行数:11,代码来源:HelloWorldInitializer.java

示例9: addDispatcherContext

import javax.servlet.ServletRegistration; //导入方法依赖的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);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:12,代码来源:SpringWebinitializer.java

示例10: dynamicServletAdded

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
/**
 * hook to register that we need to scan for security annotations.
 * @param wrapper   The wrapper for the Servlet that was added
 */
public ServletRegistration.Dynamic dynamicServletAdded(Wrapper wrapper) {
    Servlet s = wrapper.getServlet();
    if (s != null && createdServlets.contains(s)) {
        // Mark the wrapper to indicate annotations need to be scanned
        wrapper.setServletSecurityAnnotationScanRequired(true);
    }
    return new ApplicationServletRegistration(wrapper, this);
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:13,代码来源:StandardContext.java

示例11: onStartup

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx)
        throws ServletException {
    Servlet s = new TesterServlet();
    ServletRegistration.Dynamic r = ctx.addServlet("TesterServlet2", s);
    r.addMapping("/TesterServlet2");
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:8,代码来源:TesterServletContainerInitializer2.java

示例12: addServlet

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
@Override
public ServletRegistration.Dynamic addServlet(String servletName,
        String className) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (ServletRegistration.Dynamic) doPrivileged(
                "addServlet", new Object[]{servletName, className});
    } else {
        return context.addServlet(servletName, className);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:11,代码来源:ApplicationContextFacade.java

示例13: addServlet

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
@Override
public ServletRegistration.Dynamic addServlet(String servletName,
        Servlet servlet) {
    return null;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:6,代码来源:JspCServletContext.java

示例14: addServlet

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
@Override
public ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet) {
	return null;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:5,代码来源:JspCServletContext.java

示例15: addServlet

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
private ServletRegistration.Dynamic addServlet(String servletName,
        String servletClass, Servlet servlet) throws IllegalStateException {

    if (servletName == null || servletName.equals("")) {
        throw new IllegalArgumentException(sm.getString(
                "applicationContext.invalidServletName", servletName));
    }

    if (!context.getState().equals(LifecycleState.STARTING_PREP)) {
        //TODO Spec breaking enhancement to ignore this restriction
        throw new IllegalStateException(
                sm.getString("applicationContext.addServlet.ise",
                        getContextPath()));
    }

    Wrapper wrapper = (Wrapper) context.findChild(servletName);

    // Assume a 'complete' ServletRegistration is one that has a class and
    // a name
    if (wrapper == null) {
        wrapper = context.createWrapper();
        wrapper.setName(servletName);
        context.addChild(wrapper);
    } else {
        if (wrapper.getName() != null &&
                wrapper.getServletClass() != null) {
            if (wrapper.isOverridable()) {
                wrapper.setOverridable(false);
            } else {
                return null;
            }
        }
    }

    if (servlet == null) {
        wrapper.setServletClass(servletClass);
    } else {
        wrapper.setServletClass(servlet.getClass().getName());
        wrapper.setServlet(servlet);
    }

    return context.dynamicServletAdded(wrapper);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:44,代码来源:ApplicationContext.java


注:本文中的javax.servlet.ServletRegistration.Dynamic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。