本文整理汇总了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, "/*");
}
示例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);
}
示例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");
}
示例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, "/*");
}
示例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);
}
}
示例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("/");
}
示例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");
}
示例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);
}
示例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);//①
}
示例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);
}
示例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);
}
}
示例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("/");
}
示例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);
}
示例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);
}
示例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);
}