我只是创建一个简单的servlet并使用mysqldb从数据库中检索记录。我还提供了罐子"mysql-connector-java-5.1.18-bin.jar"
但是它将检索所有记录并尝试执行块而没有任何错误(没有任何SOP执行catch块)。但它仍然显示下面描述的错误。在某处,我读到了
asm-all 3.3.1.jar cglib-nodep 2.1.3.jar
。但没有任何影响
package com.sapphire.jdbcsql;
import java.io.IOException;
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 java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
/**
* Servlet implementation class ControllerServlet
*/
@WebServlet("/ControllerServlet")
public class ControllerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public ControllerServlet() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
Connection conn=null;
Statement Stat=null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Stat=conn.createStatement();
ResultSet rs=Stat.executeQuery("select * from chatbox");
while(rs.next()){
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(4));
System.out.println(rs.getString(3));
}
}
catch(Exception e){
System.out.println("a error started");
e.printStackTrace();
System.out.println("b error ended");
}
}
}
我得到以下例外:
java.lang.NoClassDefFoundError: org/objectweb/asm/commons/EmptyVisitor
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2888)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1172)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
at com.opensymphony.xwork2.util.finder.ClassFinder.readClassDef(ClassFinder.java:717)
at com.opensymphony.xwork2.util.finder.ClassFinder.<init>(ClassFinder.java:112)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.findActions(PackageBasedActionConfigBuilder.java:390)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:347)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:268)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:445)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:489)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4656)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5309)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.commons.EmptyVisitor
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
... 30 more
Jul 12, 2014 10:08:27 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 12, 2014 10:08:27 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 12, 2014 10:08:27 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 5588 ms
答案 0 :(得分:1)
由于堆栈跟踪显示Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.commons.EmptyVisitor
,这意味着你的类路径中没有asm-commons jar
只需将asm-commons.jar提供给类路径,从here获取
答案 1 :(得分:1)
这不是检索所有记录的问题,因为您的问题在此之前发生了很多。
您有一个使用opensymphony的struts2应用程序,并且您没有正确部署这些程序包,因此您会收到此错误。您需要重新访问opensymphony的文档,并确保您已正确地遵循文档,以便创建一个&#34; Hello World&#34; @WebServlet
。
然后,在此之前,您可以再次查看此代码。