SearchServlet 已由更新版本的 Java Runtime 编译
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47876051/
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
SearchServlet has been compiled by a more recent version of the Java Runtime
提问by Kyle
When I use my search feature, I get an http status 500 error. It claims that
当我使用我的搜索功能时,我收到一个 http 状态 500 错误。它声称
Error Report
HTTP Status 500 – Internal Server Error
Type Exception Report
Message SearchServlet has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [SearchServlet])
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception java.lang.UnsupportedClassVersionError: SearchServlet has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [SearchServlet]) org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2286) org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:811) org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1260) org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:488) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Unknown Source)
错误报告
HTTP 状态 500 – 内部服务器错误
类型异常报告
Message SearchServlet 已由更新版本的 Java Runtime(类文件版本 53.0)编译,此版本的 Java Runtime 仅识别最高 52.0 的类文件版本(无法加载类 [SearchServlet])
说明 服务器遇到了阻止其完成请求的意外情况。
异常 java.lang.UnsupportedClassVersionError: SearchServlet 已由更新版本的 Java Runtime(类文件版本 53.0)编译,此版本的 Java Runtime 仅识别最高 52.0 的类文件版本(无法加载类 [SearchServlet]) org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2286) org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:811) org.apache.catalina.loader.WebappClassLoaderBase.loadBase(WebappClassLoader) java:1260) org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:488) org.apache.catalina.valves.ErrorReportValve.调用(ErrorReportValve.java:81)org.apache。catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun( NioEndpoint.java:1459) org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run (来源不明)org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(来源不明)运行(未知来源)
I am using compiler compliance level 9. I have JRE 1.8 which I thought was the most recent. When I try to install Java 9, using the Eclipse Marketplace, it tells me that
我正在使用编译器合规性级别 9。我有 JRE 1.8,我认为它是最新的。当我尝试使用 Eclipse Marketplace 安装 Java 9 时,它告诉我
No repository found at
http://download.eclipse.org/eclipse/updates/none.
在以下位置找不到存储库
http://download.eclipse.org/eclipse/updates/none.
I believe, given all of this, I am completely up to date, but how am I not able to search for records in the database?
我相信,鉴于所有这些,我完全是最新的,但是我怎么不能在数据库中搜索记录?
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1" <title>Add contact to Phone Book</title>
<h1>Add contact to Phone Book</h1>
</head>
<body>
<form name="submitInfo" method="get" action="AddEntryServlet" First Name: <input type="text" name="firstName" />
<br/>
<br/>
Last Name: <input type="text" name="lastName" />
<br/>
<br/>
Area Code: <input type="number" name="areaCode" />
<br/>
<br/>
Phone Number: <input type="number" name="phoneNumber" />
<br/>
<br/>
<input type="submit" value="Submit" />
</form>
</body>
<h1>Search for Contact in Phone Book</h1>
<body>
<form name="searchInfo" method="get" action="SearchServlet">
Search First Name: <input type="text" name="searchFirstName" />
<br/>
<br/>
<input type="submit" name="action" value="search" />
</form>
</body>
</html>
Search servlet code
搜索 servlet 代码
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Query; import org.hibernate.Session;
import entities.Tbphonebook; import util.HibernateUtil;
/** * Servlet implementation class SearchServlet */
@SuppressWarnings("deprecation")
@WebServlet("/SearchServlet")
public class SearchServlet extends HttpServlet { private static final long
serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public SearchServlet() {
super();
// TODO Auto-generated constructor stub
}
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
@SuppressWarnings({ "deprecation","unchecked" })
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
String firstName = request.getParameter("searchFirstName");
@SuppressWarnings("rawtypes")
Query query = Session.createQuery("from Tbphonebook where firstname = ?");
List<Tbphonebook> persons = (List<Tbphonebook>) query.getResultList();
session.getTransaction().commit();
session.close();
request.setAttribute("persons", persons);
request.getRequestDispatcher("searchResults.jsp").forward(request,response);
response.sendRedirect("searchResults.jsp");
}
Results jsp
结果jsp
%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%> <!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=ISO-8859-1"> <title>Insert title here</title> </head>
<h1>Search Results</h1>
<h1>List Books:</h1>
<table class="table table-boardered table-striped" id="searchresults">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Area Code</th>
<th>PhoneNumber</th>
</tr>
</table>
<script>
$(document).ready(function(){
$.getJSON("persons", function(data){
var persons_data = '';
$.each(data, function(key, value){
person_date += '<tr>';
person_data += '<td>'+value.Firstname+'</td>';
person_data += '<td>'+value.Lastname+'</td>';
person_data += '<td>'+value.Areacode+'</td>';
person_data += '<td>'+value.Phonenumber+'</td>';
person_date += '</tr>';
}
);
$('#searchresults').append(persons_data);
});
});
</script>
<%
String message = (String) request.getAttribute("message");
if(!(message == null)){
out.println(message);
}else{
message= "";
out.println(message);
}
%>
</html>
采纳答案by Steve11235
"When I go to my compiler I am using compiler compliance level 9." Version 52.0 is Java 8; I assume 53.0 is Java 9. You are attempting to run code compiled for Java 9 on Java 8, which results in the error you are getting. Change your compliance version to Java 8.
“当我使用编译器时,我使用的是编译器合规性级别 9。” 版本 52.0 是 Java 8;我假设 53.0 是 Java 9。您试图在 Java 8 上运行为 Java 9 编译的代码,这会导致您遇到错误。将您的合规版本更改为 Java 8。
回答by Eric D
IDE: Eclipse Oxygen.
IDE:日食氧气。
To temporarily correct the problem do the following:
要暂时更正问题,请执行以下操作:
Project menu
> Properties
> Java Compiler
> Compiler compliance level
> 1.8
Project menu
> Properties
> Java Compiler
> Compiler compliance level
>1.8
A permanent fix likely involves installing JDK 9.
永久性修复可能涉及安装 JDK 9。
FYI 1.8 is what Java 8 is called.
仅供参考 1.8 就是 Java 8 的名称。
Side bar
侧边栏
I recently returned to Java after a foray into C# and installed Eclipse Oxygen onto a clean system that had never had Java installed on it before. This default everythingwith a brand new install of Eclipse Oxygen yet somehow or other Eclipse can't get its own parameters to match the jdk that's installed. This is the second project I created and the second time I ran into this headache.
我最近在尝试 C# 后回到 Java,并将 Eclipse Oxygen 安装到一个干净的系统上,该系统以前从未安装过 Java。这种默认的一切都与一个全新的安装Eclipse氧但不知何故或其他Eclipse不能让自己的参数匹配的已安装了JDK。这是我创建的第二个项目,也是我第二次遇到这种头痛。
回答by Oleksii Kyslytsyn
1) If you are compiling using maven plugin: try configuring your version explicitly, for example:
1) 如果您使用 maven 插件进行编译:尝试明确配置您的版本,例如:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
2) If you are compiling using automated UNIX-like OS-script, try export configuration, for example:
2) 如果您使用自动化的类 UNIX 操作系统脚本进行编译,请尝试导出配置,例如:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
3) If you are compiling using eclipse, try specifying JRE, for example:
3)如果你是用eclipse编译的,试试指定JRE,例如:
Compiling to a specific JRE with Eclipse
4) If you are compiling using NetBeans, try specifying JRE, for example:
4) 如果您使用 NetBeans 进行编译,请尝试指定 JRE,例如: