request.getServletContext()的问题!

ServletRequest的getServletContext方法是Servlet3.0添加的,这个可以看一下官方文档

http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getServletContext()

而Tomcat6只支持到Servlet2.5看它的官方文档可以知道,要用J2EE6的话得换成Tomcat7

http://tomcat.apache.org/tomcat-6.0-doc/index.html

旧版本需要先用request拿到HttpSession或者通过Servlet自身拿到ServletConfig之后再获取ServletContext

原文地址:https://www.cnblogs.com/google4y/p/3507538.html