本文整理汇总了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);
}
示例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);
}
}
示例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);
}
}
示例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());
}
示例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());
}
示例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;
}
示例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);
}
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例15: WebServletHandler
import javax.servlet.annotation.WebServlet; //导入依赖的package包/类
WebServletHandler() {
super(WebServlet.class);
}