已由最新版本的Java Runtime编译(类文件版本53.0)

时间:2017-12-18 20:37:10

标签: java eclipse hibernate jsp servlets

当我使用我的搜索功能时,我收到http状态500错误。它声称

错误报告

HTTP状态500 - 内部服务器错误

类型例外报告

消息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.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(未知来源)     java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)     org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     java.lang.Thread.run(未知来源)

当我转到我的编译器时,我正在使用编译器合规级别9.我有jre 1.8,我认为这是最新的。当我尝试使用eclipse市场安装java 9时,它告诉我在http://download.eclipse.org/eclipse/updates/none找不到存储库。

我相信鉴于所有这一切,我完全是最新的,但我怎么也无法在数据库中搜索记录?

>     <!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> <br>

搜索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");


}

结果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>

3 个答案:

答案 0 :(得分:6)

&#34;当我转到我的编译器时,我使用的是编译器合规级别9。&#34;版本52.0是Java 8;我假设53.0是Java 9.您正在尝试在Java 8上运行为Java 9编译的代码,这会导致您获得错误。将合规性版本更改为Java 8.

答案 1 :(得分:3)

IDE:Eclipse Oxygen。

要暂时解决问题,请执行以下操作:

Project menu&gt; Properties&gt; Java Compiler&gt; Compiler compliance level&gt; 1.8

永久修复可能涉及安装JDK 9。

FYI 1.8是Java 8的名称。

侧栏

我最近在进入C#后回到了Java,并将Eclipse Oxygen安装到一个之前从未安装过Java的干净系统上。这个默认一切全新安装Eclipse Oxygen,但不知何故或其他Eclipse无法获得自己的参数来匹配安装的jdk。这是我创建的第二个项目,也是我第二次遇到这个问题。

答案 2 :(得分:-1)

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)如果您使用自动类UNIX操作系统脚本进行编译,请尝试导出配置,例如:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

3)如果您正在使用eclipse进行编译,请尝试指定JRE,例如:

Compiling to a specific JRE with Eclipse

4)如果使用NetBeans进行编译,请尝试指定JRE,例如:

Netbeans - Build targetting JDK 6 but run using Java 7 JRE