我使用了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; } }
这意味着您的代码是针对正在运行它的tomcat服务器不支持的Java版本编译的。可能是您将代码移至使用Java的较早版本的tomcat的5.5以上版本。