我用这个原型创建了Servlet:http://maciejwalkowiak.github.io/servlet3-maven-archetype/
mvn archetype:generate \
-DarchetypeGroupId=pl.maciejwalkowiak \
-DarchetypeArtifactId=servlet3-webapp-archetype \
-DarchetypeVersion=1.0.1
然后我将index.jsp添加到src / main / webapp目录
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>hello, world</h1>
</body>
</html>
当我运行mvn tomcat7:run
并打开http://127.0.0.1/mycontext/index.jsp
发生此错误:
HTTP Status 500 - Unable to compile class for JSP:
type Exception report
message Unable to compile class for JSP:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 1 in the generated java file
The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:469)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
问题是什么?
我正在使用java8,但我在maven中有以下maven-compiler配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
答案 0 :(得分:2)
您应该仔细检查您的Tomcat版本。 Tomcat 7.0.32包含一个与Java 8不完全兼容的jar,因此升级Tomcat版本可能会有所帮助。看看this。
答案 1 :(得分:1)
您使用的是哪种JDK?如果是8,您还必须将Tomcat更新为8。如果情况并非如此,您应该尝试进入“项目”菜单并从那里选择“清理...”。然后尝试通过从右键单击菜单中选择这些选项来清理Server和Server Working文件夹。