问题描述
这是我尝试运行 JSP 文件时在浏览器屏幕上看到的内容.
This is what I got on the browser screen when I try to run the JSP file.
未定义 JspFactory 类型的 getJspApplicationContext(ServletContext) 方法
堆栈跟踪:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
我运行Tomcat窗口时抛出了jasper异常.
And the jasper exception is thrown on the Tomcat window when I ran it.
推荐答案
那个方法 是在 JSP 2.1 中引入的.此问题有 3 个原因:
That method was introduced in JSP 2.1. There are 3 causes for this problem:
您使用的 JSP 容器版本太旧(例如,您至少需要 Tomcat 6.0).
您在 web.xml
中声明了错误的 Servlet 版本.JSP 2.1 与 Servlet 2.5 齐头并进,因此您的 web.xml
至少应按照 Servlet 2.5 规范进行声明(为此您仍然需要一个支持 Servlet 2.5/JSP 2.1 的 servletcontainer).
You've declared the wrong Servlet version in web.xml
. JSP 2.1 goes hand in hand with Servlet 2.5, so your web.xml
should at least be declared as per the Servlet 2.5 spec (you still need a Servlet 2.5 / JSP 2.1 capable servletcontainer for that).
您已将旧版本的特定于应用程序服务器的库复制到 web 应用程序的 /WEB-INF/lib
中,例如 servlet-api.jar
、jsp-api.jar
等.你不应该永远这样做.它只会导致类加载冲突.在您的 web 项目中删除它们,并在应用服务器中保留/不接触它们.
You've duplicated older versioned appserver-specific libraries into webapp's /WEB-INF/lib
, like servlet-api.jar
, jsp-api.jar
and so on. You should never do that. It will only result in classloading collisions. Get rid of them in your webproject and leave/untouch them there in the appserver.
这篇关于方法 getJspApplicationContext(ServletContext) 未定义为 JspFactory 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!