错误说明“.class文件中的错误版本”

时间:2010-11-01 15:44:38

标签: java jsp servlets

我使用JSP代码并在tomcat5.5服务器下执行相同的操作。它被罚款了。现在我已将相同的代码复制到tomcat服务器下的其他系统。但是在提交该jsp文件时,我收到以下错误。可能是错误的原因是什么?请指教。

root cause:
javax.servlet.ServletException: Bad version number in .class file (unable to load class myfirst.SearchLink)
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.Test_jsp._jspService(Test_jsp.java:70)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

java.lang.UnsupportedClassVersionError: Bad version number in .class file (unable to load class myfirst.SearchLink)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1962)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:931)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1403)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1282)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:125)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
java.lang.ClassLoader.loadClassInternal(Unknown Source)
org.apache.jsp.Test_jsp._jspService(Test_jsp.java:51)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

更新

即使在编译了我的所有java代码之后,在当前版本的java中,我也得到了相同的错误..

最近更新

@Pangea是的,我在JSP代码中使用myfirst.SearchLink,如下所示,

myfirst.SearchLink o=new myfirst.SearchLink(); String result=o.checkURL(url);

我的SearchLink的java代码如下,

package myfirst;

import java.net.URL;
import java.net.URLConnection;
import java.sql.*;
public class SearchLink{
public static void main(String args[]) throws Exception {


}

public String checkURL(String link)throws SQLException{
    Connection con=null;
    Statement stmt=null;
    Statement stmtR=null;
    String mem;
    if(con==null){
            SQLConnection.setURL("jdbc:sqlserver://192.168.2.53\\SQL2005;user=sa;password=365media;DatabaseName=LN_ADWEEK");
            con=SQLConnection.getNewConnection();
            stmt=con.createStatement();
            stmtR=con.createStatement();
    }
    try{
        ResultSet rs;
        boolean hasRows=false;
        rs=stmt.executeQuery("select url from urls_linkins where url='"+link+"'");
        while(rs.next()){
            hasRows=true;
            //String mem=rs.getString(1);
            rs.close();
            return "This URL already exists in DB";
        }
        rs.close();
        if (!hasRows)
        {
            URL url = new URL(link);
            String domain=url.getHost();
            String Str="This URL does not exist in DB<br><br><br>";
            rs=stmtR.executeQuery("select url from urls_linkins where url like '%"+domain+"%'");
            boolean flag=false;
            while(rs.next()){
                if(!flag){
                Str=Str+"<Br>"+"Similar Domains in DB are";
                }
                flag=true;
                mem=rs.getString(1);
                //System.out.println("Similar Domains already in DB"+mem);
                Str=Str+"<Br>"+mem;
            }
            return Str;
        }
        return "This URL does not exist in DB";
    }catch(Exception e){
        e.printStackTrace();
        return e.getMessage();
    }finally{
        if(stmtR!=null){
            stmtR.close();
        }
        if(stmt!=null){
            stmt.close();
        }
        if(con!= null){
            con.close();
        }

    }
}


public String addURL(String link,String source)throws SQLException{
        Connection con=null;
        Statement stmt=null;
        Statement stmtR=null;
        final String rssvar="Rss";
        if(con==null){
                SQLConnection.setURL("jdbc:sqlserver://192.168.2.53\\SQL2005;user=sa;password=365media;DatabaseName=LN_ADWEEK");
                con=SQLConnection.getNewConnection();
                stmt=con.createStatement();
                stmtR=con.createStatement();
    }
        try{
            PreparedStatement insertUrlStatement = con.prepareStatement("INSERT INTO urls_linkins(url, source_name, is_active, is_periodic, Link_Type, New_Entry) VALUES(?, ?, ?, ?, ?, ?)");
            //insertUrlStatement.setInt(1, 21211);
            insertUrlStatement.setString(1, link);
            insertUrlStatement.setString(2, source);
            insertUrlStatement.setInt(3, 1);
            insertUrlStatement.setInt(4, 0);
            insertUrlStatement.setString(5, rssvar);
            insertUrlStatement.setInt(6, 1);
            insertUrlStatement.executeUpdate();
            insertUrlStatement.close();
            return "The URL has been added to the Database";}
        catch(Exception e){
            e.printStackTrace();
            return e.getMessage();
        }finally{
            if(stmtR!=null){
                stmtR.close();
            }
            if(stmt!=null){
                stmt.close();
            }
            if(con!= null){
                con.close();
            }
        }


}

public String addURL1(String link,String source)throws SQLException{
        Connection con=null;
        Statement stmt=null;
        Statement stmtR=null;
        final String other="Other";
        if(con==null){
                SQLConnection.setURL("jdbc:sqlserver://192.168.2.53\\SQL2005;user=sa;password=365media;DatabaseName=LN_ADWEEK");
                con=SQLConnection.getNewConnection();
                stmt=con.createStatement();
                stmtR=con.createStatement();
    }
        try{
            PreparedStatement insertUrlStatement = con.prepareStatement("INSERT INTO urls_linkins(url, source_name, is_active, is_periodic, Link_Type, New_Entry) VALUES(?, ?, ?, ?, ?, ?)");
            //insertUrlStatement.setInt(1, 21211);
            insertUrlStatement.setString(1, link);
            insertUrlStatement.setString(2, source);
            insertUrlStatement.setInt(3, 1);
            insertUrlStatement.setInt(4, 0);
            insertUrlStatement.setString(5, other);
            insertUrlStatement.setInt(6, 1);
            insertUrlStatement.executeUpdate();
            insertUrlStatement.close();
            return "The URL has been added to the Database";}
        catch(Exception e){
            e.printStackTrace();
            return e.getMessage();
        }finally{
            if(stmtR!=null){
                stmtR.close();
            }
            if(stmt!=null){
                stmt.close();
            }
            if(con!= null){
                con.close();
            }
        }
}

public String addmultiple(String file)throws SQLException{
        return file;
}
}

3 个答案:

答案 0 :(得分:4)

这意味着您的代码是根据您运行它的tomcat服务器不支持的java版本编译的。可能是您将代码移动到使用旧版本java的旧版本的tomcat而不是5.5

答案 1 :(得分:2)

您在旧的JVM版本上运行了较新版本的代码(例如,在JDK 4上运行Java 5代码)。我假设其他Tomcat运行的是旧版本的java,而不是运行在Tomcat 5.5服务器上的java。

答案 2 :(得分:0)

我有同样的例外,但我更改了以下设置,这对我有用:

  • 右键单击您的eclipse项目选择属性
  • 弹出将显示所有设置树选择Java编译器
  • 然后根据需要选择编译器合规性级别下拉列表并再次选择“构建项目”
  • 重启tomcat(我曾经使用过tomcat 6)