6

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>
Vega
  • 27,856
  • 27
  • 95
  • 103
Kyle
  • 99
  • 1
  • 1
  • 5
  • 2
    Please take some time to format your question. What you've got right now is virtually unreadable. – azurefrog Dec 18 '17 at 20:40
  • 2
    Looks like you're trying to run something compiled w/ a later version of Java on an earlier version of Java, and the compilation didn't target the earlier version. Kind of like the message says. All that other information isn't useful (besides being illegible, consider code formatting the... well, code.) – Dave Newton Dec 18 '17 at 20:42
  • For next time, instead of putting `>` on every line, just indent all your code by 4 spaces. There is even a `{}` button in the editor to do that for you. – takendarkk Dec 18 '17 at 20:44
  • Pretty sure u use a [Java 9 library](https://stackoverflow.com/questions/9170832/list-of-java-class-file-format-major-version-numbers) with a java 8 JVM – Christian Kuetbach Dec 18 '17 at 21:18
  • Sorry about the bad format initially. I believe it was something with Java compiling I ended up creating a new project and copying the code and everything worked fine. Not the best solution but it worked. – Kyle Dec 20 '17 at 21:17

3 Answers3

7

"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.

Steve11235
  • 2,849
  • 1
  • 17
  • 18
5

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.

Eric D
  • 1,363
  • 13
  • 9
-2

1) If you are compiling using maven plugin: try configuring your version explicitly, for example:

<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:

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

3) If you are compiling using eclipse, try specifying JRE, for example:

Compiling to a specific JRE with Eclipse

4) If you are compiling using NetBeans, try specifying JRE, for example:

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

Oleksii Kyslytsyn
  • 2,458
  • 2
  • 27
  • 43