本文整理汇总了Java中org.apache.catalina.deploy.FilterMap.addServletName方法的典型用法代码示例。如果您正苦于以下问题:Java FilterMap.addServletName方法的具体用法?Java FilterMap.addServletName怎么用?Java FilterMap.addServletName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.catalina.deploy.FilterMap
的用法示例。
在下文中一共展示了FilterMap.addServletName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startTomcat
import org.apache.catalina.deploy.FilterMap; //导入方法依赖的package包/类
protected void startTomcat() throws Exception {
tomcat = new Tomcat();
File base = new File(System.getProperty("java.io.tmpdir"));
org.apache.catalina.Context ctx =
tomcat.addContext("/foo",base.getAbsolutePath());
FilterDef fd = new FilterDef();
fd.setFilterClass(TestFilter.class.getName());
fd.setFilterName("TestFilter");
FilterMap fm = new FilterMap();
fm.setFilterName("TestFilter");
fm.addURLPattern("/*");
fm.addServletName("/bar");
ctx.addFilterDef(fd);
ctx.addFilterMap(fm);
tomcat.addServlet(ctx, "/bar", TestServlet.class.getName());
ctx.addServletMapping("/bar", "/bar");
host = "localhost";
port = getLocalPort();
tomcat.setHostname(host);
tomcat.setPort(port);
tomcat.start();
}
示例2: addMappingForServletNames
import org.apache.catalina.deploy.FilterMap; //导入方法依赖的package包/类
@Override
public void addMappingForServletNames(
EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
String... servletNames) {
FilterMap filterMap = new FilterMap();
filterMap.setFilterName(filterDef.getFilterName());
if (dispatcherTypes != null) {
for (DispatcherType dispatcherType : dispatcherTypes) {
filterMap.setDispatcher(dispatcherType.name());
}
}
if (servletNames != null) {
for (String servletName : servletNames) {
filterMap.addServletName(servletName);
}
if (isMatchAfter) {
context.addFilterMap(filterMap);
} else {
context.addFilterMapBefore(filterMap);
}
}
// else error?
}
示例3: doTest
import org.apache.catalina.deploy.FilterMap; //导入方法依赖的package包/类
private void doTest(String encoding, String expected, int mode)
throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
// Add the Servlet
CharsetServlet servlet = new CharsetServlet(mode);
Tomcat.addServlet(ctx, "servlet", servlet);
ctx.addServletMapping("/", "servlet");
// Add the Filter
FilterDef filterDef = new FilterDef();
filterDef.setFilterClass(AddDefaultCharsetFilter.class.getName());
filterDef.setFilterName("filter");
if (encoding != null) {
filterDef.addInitParameter("encoding", encoding);
}
ctx.addFilterDef(filterDef);
FilterMap filterMap = new FilterMap();
filterMap.setFilterName("filter");
filterMap.addServletName("servlet");
ctx.addFilterMap(filterMap);
tomcat.start();
Map<String, List<String>> headers = new HashMap<String, List<String>>();
getUrl("http://localhost:" + getPort() + "/", new ByteChunk(), headers);
List<String> ctHeaders = headers.get("Content-Type");
assertEquals(1, ctHeaders.size());
String ct = ctHeaders.get(0);
assertEquals("text/plain;charset=" + expected, ct);
}
示例4: addMappingForServletNames
import org.apache.catalina.deploy.FilterMap; //导入方法依赖的package包/类
@Override
public void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
String... servletNames) {
FilterMap filterMap = new FilterMap();
filterMap.setFilterName(filterDef.getFilterName());
if (dispatcherTypes != null) {
for (DispatcherType dispatcherType : dispatcherTypes) {
filterMap.setDispatcher(dispatcherType.name());
}
}
if (servletNames != null) {
for (String servletName : servletNames) {
filterMap.addServletName(servletName);
}
if (isMatchAfter) {
context.addFilterMap(filterMap);
} else {
context.addFilterMapBefore(filterMap);
}
}
// else error?
}