小编典典

SearchServlet已由Java Runtime的最新版本进行编译

hibernate

使用搜索功能时,出现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(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。
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 Marketplace安装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>

搜索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>

阅读 411

收藏
2020-06-20

共1个答案

小编典典

“当我使用编译器时,我正在使用编译器符合性级别9。” 52.0版是Java 8;我假设53.0是Java9。您正在尝试在Java 8上运行针对Java
9编译的代码,这会导致出现错误。将您的合规性版本更改为Java 8。

2020-06-20