eclipse 方法 getJspApplicationContext(ServletContext) 未定义为 JspFactory 类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2327118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
提问by Hariharbalaji
This is what I got on the browser screen when I try to run the JSP file.
这是我尝试运行 JSP 文件时在浏览器屏幕上看到的内容。
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
方法 getJspApplicationContext(ServletContext) 未定义为 JspFactory 类型
Stacktrace:
堆栈跟踪:
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)
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.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。编译(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)
And the jasper exception is thrown on the Tomcat window when I ran it.
当我运行它时,在 Tomcat 窗口上抛出了 jasper 异常。
回答by BalusC
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
方法 getJspApplicationContext(ServletContext) 未定义为 JspFactory 类型
That methodwas introduced in JSP 2.1. There are 3 causes for this problem:
该方法是在 JSP 2.1 中引入的。这个问题有3个原因:
You're using an too old version of the JSP container (you need for example at least Tomcat 6.0).
You've declared the wrong Servlet version in
web.xml
. JSP 2.1 goes hand in hand with Servlet 2.5, so yourweb.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).You've duplicated older versioned appserver-specific libraries into webapp's
/WEB-INF/lib
, likeservlet-api.jar
,jsp-api.jar
and so on. You should neverdo that. It will only result in classloading collisions. Get rid of them in your webproject and leave/untouch them there in the appserver.
您使用的 JSP 容器版本太旧(例如,您至少需要Tomcat 6.0)。
您在
web.xml
. JSP 2.1 与 Servlet 2.5 齐头并进,因此您web.xml
至少应该按照 Servlet 2.5 规范进行声明(为此您仍然需要一个支持 Servlet 2.5 / JSP 2.1 的 servletcontainer)。你复制旧的版本,具体的应用服务器库到Web应用的
/WEB-INF/lib
,比如servlet-api.jar
,jsp-api.jar
等等。你永远不应该那样做。它只会导致类加载冲突。在您的 web 项目中摆脱它们,并在应用程序服务器中保留/取消它们。
回答by Ratshi?aho Wayne
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
also fixes the issues
也解决了问题
回答by mmaceachran
For Maven, I also had to add the jsp-api dependency as a provided jar like this: (Some other dependency was pulling it in, I could never figure out which one, but this fixed it up)
对于 Maven,我还必须将 jsp-api 依赖项添加为提供的 jar,如下所示:(其他一些依赖项正在拉入它,我永远无法弄清楚是哪一个,但这修复了它)
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
回答by Brad Parks
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
方法 getJspApplicationContext(ServletContext) 未定义为 JspFactory 类型
This can also happen when your project requires a reference to a server runtime:
当您的项目需要对服务器运行时的引用时,也会发生这种情况:
- Right click on your project in Eclipse's "Project Explorer"
- Choose "Build Path | Configure Build Path"
- Click on the "Libraries" tab
- Click "Add Library"
- Select "Server Runtime" and click "Next"
- Choose "Apache Tomcat 7", or whatever your server runtime version should be.
- 在 Eclipse 的“项目资源管理器”中右键单击您的项目
- 选择“构建路径|配置构建路径”
- 单击“库”选项卡
- 点击“添加库”
- 选择“服务器运行时”,然后单击“下一步”
- 选择“Apache Tomcat 7”,或任何您的服务器运行时版本。
Note: This error can also happen for ANT builds, and for that case, you need to reference a target runtime in your ANT build.xml file... The following references a local tomcat installation, and uses its "lib" folders when doing the compile:
注意:ANT 构建也可能发生此错误,对于这种情况,您需要在 ANT build.xml 文件中引用目标运行时...以下引用本地 tomcat 安装,并在执行时使用其“lib”文件夹编译:
<project name="tomcat-demo" default="compile" basedir=".">
<property name="tomcat-home" value="/path/to/your/tomcat/apache-tomcat-7" />
<path id="project-classpath">
<fileset dir="WebContent/WEB-INF/lib" includes="*.jar" />
<fileset dir="${tomcat-home}/bin" includes="*.jar" />
<fileset dir="${tomcat-home}/common/lib" includes="*.jar" />
<fileset dir="${tomcat-home}/server/lib" includes="*.jar" />
</path>
...
</project>
Snagged from this url:
来自这个网址: