SearchServlet has been compiled by a more recent version of the Java Runtime
Solution 1
"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.
Solution 2
IDE: Eclipse Oxygen.
To temporarily correct the problem do the following:
Project menu
> Properties
> Java Compiler
> Compiler compliance level
> 1.8
A permanent fix likely involves installing JDK 9.
FYI 1.8 is what Java 8 is called.
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 everything with 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.
Kyle
Updated on August 19, 2020Comments
-
Kyle over 3 years
When I use my search feature, I get an http status 500 error. It claims that
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)
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
No repository found at
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
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
%@ 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>