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


Java WebServlet類代碼示例

本文整理匯總了Java中javax.servlet.annotation.WebServlet的典型用法代碼示例。如果您正苦於以下問題:Java WebServlet類的具體用法?Java WebServlet怎麽用?Java WebServlet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WebServlet類屬於javax.servlet.annotation包,在下文中一共展示了WebServlet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toMappedServlet

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
public MappedServlet toMappedServlet(Servlet servlet) {

		WebServlet wsAnnotation = servlet.getClass().getAnnotation(WebServlet.class);

		if (wsAnnotation == null) {
			throw new IllegalArgumentException(
					"Servlet contains no @WebServlet annotation and can not be mapped directly. Wrap it in a MappedServlet instead.");
		}

		String name = wsAnnotation.name() != null && wsAnnotation.name().length() > 0 ? wsAnnotation.name() : null;
		Set<String> urlPatterns = new HashSet<>(asList(wsAnnotation.urlPatterns()));

		Map<String, String> initParams = new HashMap<>();

		WebInitParam[] paramsArray = wsAnnotation.initParams();
		if (paramsArray != null) {
			asList(paramsArray).forEach(p -> initParams.put(p.name(), p.value()));
		}

		return new MappedServlet(servlet, urlPatterns, name, initParams);
	}
 
開發者ID:bootique,項目名稱:bootique-jetty,代碼行數:22,代碼來源:MappedServletFactory.java

示例2: registerJeeComponents

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
private void registerJeeComponents(ConfigurableListableBeanFactory beanFactory, ClassLoader cl,
		Set<BeanDefinition> candiates) {

	for (BeanDefinition bd : candiates) {

		try {
			Class<?> beanClass = ClassUtils.forName(bd.getBeanClassName(), cl);
			WebServlet webServlet = beanClass.getDeclaredAnnotation(WebServlet.class);
			WebFilter webFilter = beanClass.getDeclaredAnnotation(WebFilter.class);
			WebListener webListener = beanClass.getDeclaredAnnotation(WebListener.class);

			DefaultListableBeanFactory targetBeanFactory = (DefaultListableBeanFactory) beanFactory;

			if (webServlet != null) {
				createAndRegisterServletBean(targetBeanFactory, bd, beanClass, webServlet);
			} else if (webFilter != null) {
				createAndRegisterServletFilterBean(targetBeanFactory, bd, beanClass, webFilter);
			} else if (webListener != null) {
				createAndRegisterWebListenerBean(targetBeanFactory, bd, beanClass, webListener);
			}

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
}
 
開發者ID:thomasdarimont,項目名稱:spring-boot-jee-web-example,代碼行數:27,代碼來源:JeeComponentsBeanFactoryPostProcessor.java

示例3: getBasePath

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
public String getBasePath() {
	WebServlet webServlet = this.servlet.getClass().getAnnotation(WebServlet.class);
	String path = null;
	
	if (webServlet.value().length > 0 ) {
		path = webServlet.value()[0];
	}
	if(webServlet.urlPatterns().length>0){
		path = webServlet.urlPatterns()[0];
	}
	if(null == path) {
		return null;
	}
	if (!path.endsWith("/*")) {
		return "";
	} else {
		return path.substring(0, path.length() - 2);
	}

}
 
開發者ID:rock-java,項目名稱:servletplus,代碼行數:21,代碼來源:Router.java

示例4: install

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
@Override
public void install(final Environment environment, final HttpServlet instance) {
    final Class<? extends HttpServlet> extType = FeatureUtils.getInstanceClass(instance);
    final WebServlet annotation = FeatureUtils.getAnnotation(extType, WebServlet.class);
    final String[] patterns = annotation.urlPatterns().length > 0 ? annotation.urlPatterns() : annotation.value();
    Preconditions.checkArgument(patterns.length > 0,
            "Servlet %s not specified url pattern for mapping", extType.getName());
    final AdminContext context = FeatureUtils.getAnnotation(extType, AdminContext.class);
    final String name = WebUtils.getServletName(annotation, extType);
    reporter.line("%-15s %-5s %-2s (%s)   %s", Joiner.on(",").join(patterns),
            WebUtils.getAsyncMarker(annotation), WebUtils.getContextMarkers(context), extType.getName(), name);

    if (WebUtils.isForMain(context)) {
        configure(environment.servlets(), instance, extType, name, annotation);
    }
    if (WebUtils.isForAdmin(context)) {
        configure(environment.admin(), instance, extType, name, annotation);
    }
}
 
開發者ID:xvik,項目名稱:dropwizard-guicey,代碼行數:20,代碼來源:WebServletInstaller.java

示例5: configure

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
private void configure(final ServletEnvironment environment, final HttpServlet servlet,
                       final Class<? extends HttpServlet> type, final String name, final WebServlet annotation) {
    final ServletRegistration.Dynamic mapping = environment.addServlet(name, servlet);
    final Set<String> clash = mapping
            .addMapping(annotation.urlPatterns().length > 0 ? annotation.urlPatterns() : annotation.value());
    if (clash != null && !clash.isEmpty()) {
        final String msg = String.format(
                "Servlet registration %s clash with already installed servlets on paths: %s",
                type.getSimpleName(), Joiner.on(',').join(clash));
        if (option(DenyServletRegistrationWithClash)) {
            throw new IllegalStateException(msg);
        } else {
            logger.warn(msg);
        }
    }
    if (annotation.initParams().length > 0) {
        for (WebInitParam param : annotation.initParams()) {
            mapping.setInitParameter(param.name(), param.value());
        }
    }
    mapping.setAsyncSupported(annotation.asyncSupported());
}
 
開發者ID:xvik,項目名稱:dropwizard-guicey,代碼行數:23,代碼來源:WebServletInstaller.java

示例6: printServletInfo

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
protected void printServletInfo() {
	Class<?> clazz = this.getClass();
	WebServlet servlet = clazz.getAnnotation(WebServlet.class);
	if (servlet == null) {
		return;
	}
	String name = servlet.name();
	String uri = StringUtils.arrayToDelimitedString(servlet.urlPatterns(), ",");
	System.err.println("WebServlet name:" + name + "\turi:" + uri + "\tclass:" + clazz.getName());
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:11,代碼來源:AbstractHttpServlet.java

示例7: findServletTypes

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
private List<Class<?>> findServletTypes() {
    ReflectionsHelper.registerUrlTypes();
    Reflections reflections = new Reflections(scanPkgNames.toArray());
    Set<Class<?>> types = reflections.getTypesAnnotatedWith(WebServlet.class);
    List<Class<?>> result = new ArrayList<>();
    for(Class<?> type : types) {
        if(Servlet.class.isAssignableFrom(type)) {
            result.add(type);
        }
    }
    return result;
}
 
開發者ID:flipkart-incubator,項目名稱:polyguice,代碼行數:13,代碼來源:PolyguiceApp.java

示例8: addServletWithMapping

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void addServletWithMapping(ServletHandler sh, Class type){
	WebServlet annotation = (WebServlet)type.getAnnotation(WebServlet.class);
	String[] paths = annotation.value();
	for (String path : paths) {
		sh.addServletWithMapping(type, path);			
	}
}
 
開發者ID:edolganov,項目名稱:live-chat-engine,代碼行數:9,代碼來源:FrontAndChats_IntegrationTest.java

示例9: createAndRegisterServletBean

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
private void createAndRegisterServletBean(DefaultListableBeanFactory defaultListeableBeanFactory, BeanDefinition bd,
		Class<?> beanClass, WebServlet webServlet) {

	BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ServletRegistrationBean.class);
	builder.addPropertyValue("servlet", bd);
	builder.addPropertyValue("urlMappings", new LinkedHashSet<>(Arrays.asList(webServlet.urlPatterns())));

	String beanName = webServlet.name().isEmpty() ? StringUtils.uncapitalize(beanClass.getSimpleName()) : webServlet
			.name();
	defaultListeableBeanFactory.registerBeanDefinition(beanName, builder.getBeanDefinition());
}
 
開發者ID:thomasdarimont,項目名稱:spring-boot-jee-web-example,代碼行數:12,代碼來源:JeeComponentsBeanFactoryPostProcessor.java

示例10: isAsyncSupported

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
@EvoSuiteAssertionOnly
@Override
public boolean isAsyncSupported() {
	Servlet sut = EvoServletState.getServlet();
	WebServlet annotation = sut.getClass().getAnnotation(WebServlet.class);
	if(annotation == null){
		return false; //TODO: unsure if really correct. need more investigation
	}
	return annotation.asyncSupported();
}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:11,代碼來源:EvoHttpServletRequest.java

示例11: addServlet

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
private String addServlet(Servlet servlet) {
    Class<?> clz = servlet.getClass();
    WebServlet ann = clz.getAnnotation(WebServlet.class);
    if (ann == null) {
        return null;
    }
    String name = ann.name();
    DynamicSRegistration reg = addServlet(name, servlet);
    if (reg == null) {
        return null;
    }
    doParameters(reg, ann.initParams());
    reg.addMapping(ann.urlPatterns());
    return name;
}
 
開發者ID:arievanwi,項目名稱:osgi.ee,代碼行數:16,代碼來源:OurServletContext.java

示例12: init

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
@PostConstruct
public void init() {
    logger.info("Starting undertow w/ resteasy support.");
    WebServlet resteasyServlet = new WebServletLiteral("RestEasy",new String[]{"/"},
            new WebInitParam[]{},true,1);
    Map<String,Object> servletContextParams = new HashMap<>();
    servletContextParams.put(ResteasyDeployment.class.getName(), createDeployment());
    undertowComponent = new UndertowComponent(httpListenPort,httpListenAddress,contextRoot,deploymentName)
            .addServlet(resteasyServlet,HttpServlet30Dispatcher.class)
            .setWebSocketEndpoint(CourseServer.class)
            .addListener(RequestScopedServletRequestListener.class)
            .start(servletContextParams);
    logger.info("Container up and running on port "+httpListenPort);
}
 
開發者ID:johnament,項目名稱:restful-and-beyond-tut2184,代碼行數:15,代碼來源:Listener.java

示例13: startUndertow

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
public void startUndertow(@Observes ApplicationStartupEvent applicationStartupEvent) {
    WebServlet resteasyServlet = new WebServletLiteral("RestEasy",new String[]{"/"},
            new WebInitParam[]{},true,1);
    Map<String,Object> servletContextParams = new HashMap<>();
    servletContextParams.put(ResteasyDeployment.class.getName(), createDeployment());
    undertowComponent = new UndertowComponent(undertowBindPort,undertowBindAddress,contextRoot,deploymentName)
            .addServlet(resteasyServlet,HttpServlet30Dispatcher.class)
            .addListener(RequestScopedServletRequestListener.class)
            .start(servletContextParams);
}
 
開發者ID:johnament,項目名稱:restful-and-beyond-tut2184,代碼行數:11,代碼來源:SecureServer.java

示例14: procesServlets

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
private void procesServlets() {
    Consumer<Class<? extends HttpServlet>> c = servlet -> {
        WebServlet webServlet = ClassUtils.getAnnotation(servlet, WebServlet.class);
        if(webServlet != null) {
            ServletDescriptor servletDescriptor = new ServletDescriptor(webServlet.name(),
                    webServlet.value(), mapUrls(webServlet.urlPatterns()), webServlet.loadOnStartup(),
                    webServlet.initParams(),webServlet.asyncSupported(),servlet);
            webServer.addServlet(servletDescriptor);
        }
    };
    extension.processServlets(c);
}
 
開發者ID:hammock-project,項目名稱:hammock,代碼行數:13,代碼來源:StartWebServer.java

示例15: WebServletHandler

import javax.servlet.annotation.WebServlet; //導入依賴的package包/類
WebServletHandler() {
    super(WebServlet.class);
}
 
開發者ID:PebbleTemplates,項目名稱:pebble-spring-boot-starter,代碼行數:4,代碼來源:WebServletHandler.java


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