Current container detection is based on classes present in classpath, so simple method is use class that present in Tomcat container but not in generic servlet-container targeted artifacts. ServletRequest/ServletResponse impl classes are specific for concrete servlet container (so they shouldn't present in other containers if they aren't forks of Tomcat). Also, they aren't in tomcat-api.jar and its dependencies.
Maybe such detection mechanism is fragile (because impl classes can change in future) but it's very simple. Using of ServletContext.getServerInfo() can give false positives and negatives too and requires some testing in popular servlet containers, of course. You decide what fix to use. =)
|