开发者

Servlet Compiling error

I developed simple servlet using Apache Tomcat 6.

Firstly I write simple Hello World print servlet. Then set CLASSPATH for servlet-api.jar and compile and copy webapps/login/WEB-INF/classes/test/HelloServlet.class. That's working fine.

After I write simple JDBC connection in the servlet. I downloaded MySQL J-Connector and set CLASSPATH like this:

C:\Program Files\apache-tomcat-6.0.32\lib\servlet-api.jar;C:\Program Files\apache-tomcat-6.0.32\lib\mysql-connector-java-5.1.16-bin.jar

then try to compile; it then shows the following message:

"Unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown"

How shoul开发者_Python百科d I solve that?


Keep your Class.forName() under try catch block & classpath should ends with (.;) check it once.


java.lang.ClassNotFoundException is a checked exception. That means that you are required to deal with it, either by putting the call that may throw this exception inside a try { ... } catch (ClassNotFoundException e) { ... } block or by adding a throws clause to the method declaration of the method in which you make the call to the method that may throw this exception.

Read more about dealing with checked exceptions in The Catch or Specify Requirement in Oracle's Java Tutorials.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜