这个运行时错误发生在我的 spring mvc 项目中。目标服务器apache tomcat 8.0。你能帮我解决这个问题吗:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [31] in the generated java file: [C:\Users\mehrdad\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\CPNC\org\apache\jsp\pages\home_jsp.java]
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
An error occurred at line: [42] in the generated java file: [C:\Users\mehrdad\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\CPNC\org\apache\jsp\pages\home_jsp.java]
The method getDispatcherType() is undefined for the type HttpServletRequest
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:199)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:450)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:361)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
这是 home.jsp:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Home page</title>
</head>
<body>
<h1>Home page</h1>
<p>This is Home page. It's available for all users.<br/>
<a href="${pageContext.request.contextPath}/sec/moderation.html">Moderation page</a><br/>
<a href="${pageContext.request.contextPath}/admin/first.html">First Admin page</a><br/>
<a href="${pageContext.request.contextPath}/admin/second.html">Second Admin page</a><br/>
</p>
</body>
</html>
最佳答案
从生成的 WAR 文件中删除 javax.servlet-api
、servlet-api
、jsp-api
、jSTL
库。这些库应该在编译时使用,但不应包含在 WAR 存档中。编译 JSP 文件的服务器(例如 Tomcat)提供这些依赖项。您的库优先于服务器提供的库,这会导致错误。
如果您使用 Maven 或 Gradle,请将依赖项范围设置为 provided
值。
关于java - Spring Web 应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28440734/