Home > Back-end >  Rookie help, can you tell me the Servlet DAO cannot use is what went wrong?
Rookie help, can you tell me the Servlet DAO cannot use is what went wrong?

Time:10-31

This application is a simple taobao: search by name, and paging display, a page display 10
I made of hierarchical way, general idea from an HTML to send search keywords to the Servlet, the Servlet then use the DAO to look for in the database, and the results stored in the List, the last to find as a result, the current page number, total number of pages with a request to the JSP

I now the DAO can run of success:

As shown, is stored in the database of the commodity serial number, name and price, for the convenience, all names begin with pen, pen to find the key word, found a total of 32 results, and successfully showed before ten,

But the same code in the Servlet, an error:
Java. Lang. ClassNotFoundException: com. Mysql.. JDBC Driver
The at org. Apache. Catalina. Loader. WebappClassLoader. LoadClass (WebappClassLoader. Java: 1680)
The at org. Apache. Catalina. Loader. WebappClassLoader. LoadClass (WebappClassLoader. Java: 1526)
The at Java. Lang. Class. ForName0 (Native Method)
The at Java. Lang. Class.forname (Unknown Source)
The at dao. BaseDAO. OpenCon (BaseDAO. Java: 9)
The at dao. GoodsDAO. CountByKeyword (GoodsDAO. Java: 14)
The at servlets. PageQueryDO. DoPost (PageQueryDO. Java: 45)
The at javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 643)
The at javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 723)
The at org. Apache. Catalina. Core. ApplicationFilterChain. InternalDoFilter (ApplicationFilterChain. Java: 290)
The at org. Apache. Catalina. Core. ApplicationFilterChain. DoFilter (ApplicationFilterChain. Java: 206)
The at org. Apache. Catalina. Core. StandardWrapperValve. Invoke (StandardWrapperValve. Java: 233)
The at org. Apache. Catalina. Core. StandardContextValve. Invoke (StandardContextValve. Java: 191)
The at org. Apache. Catalina. Core. StandardHostValve. Invoke (StandardHostValve. Java: 127)
The at org. Apache. Catalina. Valves. ErrorReportValve. Invoke (ErrorReportValve. Java: 103)
The at org. Apache. Catalina. Core. StandardEngineValve. Invoke (StandardEngineValve. Java: 109)
At org. Apache. Catalina. Connector. CoyoteAdapter. Service (293) CoyoteAdapter. Java:
The at org. Apache. Coyote. Http11. Http11Processor. Process (Http11Processor. Java: 861)
The at org. Apache. Coyote. Http11. Http11Protocol $Http11ConnectionHandler. Process (Http11Protocol. Java: 606)
At org.apache.tomcat.util.net.JIoEndpoint$Worker.run JIoEndpoint. Java: (489)
The at Java. Lang. Thread. The run (Unknown Source)
Java. Lang. NullPointerException
The at dao. GoodsDAO. CountByKeyword (GoodsDAO. Java: 16)
The at servlets. PageQueryDO. DoPost (PageQueryDO. Java: 45)
The at javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 643)
The at javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 723)
The at org. Apache. Catalina. Core. ApplicationFilterChain. InternalDoFilter (ApplicationFilterChain. Java: 290)
The at org. Apache. Catalina. Core. ApplicationFilterChain. DoFilter (ApplicationFilterChain. Java: 206)
The at org. Apache. Catalina. Core. StandardWrapperValve. Invoke (StandardWrapperValve. Java: 233)
The at org. Apache. Catalina. Core. StandardContextValve. Invoke (StandardContextValve. Java: 191)
The at org. Apache. Catalina. Core. StandardHostValve. Invoke (StandardHostValve. Java: 127)
The at org. Apache. Catalina. Valves. ErrorReportValve. Invoke (ErrorReportValve. Java: 103)
The at org. Apache. Catalina. Core. StandardEngineValve. Invoke (StandardEngineValve. Java: 109)
At org. Apache. Catalina. Connector. CoyoteAdapter. Service (293) CoyoteAdapter. Java:
The at org. Apache. Coyote. Http11. Http11Processor. Process (Http11Processor. Java: 861)
The at org. Apache. Coyote. Http11. Http11Protocol $Http11ConnectionHandler. Process (Http11Protocol. Java: 606)
At org.apache.tomcat.util.net.JIoEndpoint$Worker.run JIoEndpoint. Java: (489)
The at Java. Lang. Thread. The run (Unknown Source)

The doPost method of the Servlet is like this:
Protected void doPost (it request, HttpServletResponse response) throws ServletException, IOException {
//TODO Auto - generated method stub
String keyword=request. The getParameter (" keyword ");
Int page=Integer. ParseInt (request. The getParameter (" page "));
GoodsDAO dao=new GoodsDAO ();
Int totalCount=dao. CountByKeyword (keyword);//in the database to find there are a few relevant results
Int totalPage=totalCount/10;//paging display
If (totalCount % 10 & gt; 0)
{
TotalPage +=1;
}
ArrayList Result=new ArrayList (a);
Int startIndex=10 * (page 1);
Result=dao. ReturnResult (keyword, startIndex, 10);//will database search results into the result to the
Request. SetAttribute (" result ", result);//ready to preach to the JSP
Request. SetAttribute (" totalPage ", totalPage);
Request. SetAttribute (" CurrentPage ", 1);
String Page="goods. JSP";
RequestDispatcher rd=request. GetRequestDispatcher (Page);
Rd. Forward (request, response);
}
Don't know exactly where a mistake? It shows that is a question of JDBC, but why the DAO can run their own... Write other similar programs also met this problem before, restart eclipse miraculously ok...
Rookie to post for the first time, if you have any format error please understand, please great god TAT correct guidance

CodePudding user response:

Lack the jar package, mysql connector - Java. The jar, and this problem can be directly baidu to faster,

CodePudding user response:

   nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related