java web http 500_[转载]JAVA-Web错误之“HTTP Status 500

具体报错如下:

HTTP Status 500 - Servlet execution threw an exception

type Exception report

message Servlet execution threw an exception

description The server encountered an internal error

that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception

org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z

org.apache.tomcat.dbcp.dbcp2.DelegatingConnection.isValid(DelegatingConnection.java:913)

org.apache.tomcat.dbcp.dbcp2.PoolableConnection.validate(PoolableConnection.java:226)

org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:302)

org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2208)

org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2191)

org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:1945)

org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1412)

Dao.DBConnectionFromPool.(DBConnectionFromPool.java:16)

Dao.DBConnectionFromPool.(DBConnectionFromPool.java:10)

Dao.JdbcTools.getConnectionFromPool(JdbcTools.java:16)

Dao.UserDao.(UserDao.java:16)

Servlet.RegServlet.doPost(RegServlet.java:36)

javax.servlet.http.HttpServlet.service(HttpServlet.java:648)

javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

note The full stack trace of the root cause is

available in the Apache Tomcat/8.0.21 logs.

Apache Tomcat/8.0.21

出现错误场景:

在另外的电脑上测试过是可以正常运行的,但是,换到自己电脑上就出现此类错误,主要原因是Tomcat、mysql-connector-java、jdk几个之间的版本不匹配。

个人推测比较有可能是mysql-connector-java和tomacat版本不匹配,但是不能肯定。(更确切的原因目前也还是不知道)

我最初的配置是:

JDK:1.7.0.67

jre1.7

tomcat 8.0.21

mysql-connector-java 5.0.4

解决方法如下:

一、更改了tomcat的版本为apache-tomcat-7.0.64

二、更改mysql-connector-java版本为5.1.24

二者选其一即可。

ps:写入数据库的时候用到了数据连接池,如果不使用数据连接池的话不会有这个问题。

具体报错如下: HTTP Status 500 - Servlet execution threw an exception type Exception report message Servlet execution threw an exception description The server encountered an internal error that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet execution threw an exception org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z org.apache.tomcat.dbcp.dbcp2.DelegatingConnection.isValid(DelegatingConnection.java:913) org.apache.tomcat.dbcp.dbcp2.PoolableConnection.validate(PoolableConnection.java:226) org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:302) org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2208) org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2191) org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:1945) org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1412) Dao.DBConnectionFromPool.(DBConnectionFromPool.java:16) Dao.DBConnectionFromPool.(DBConnectionFromPool.java:10) Dao.JdbcTools.getConnectionFromPool(JdbcTools.java:16) Dao.UserDao.(UserDao.java:16) Servlet.RegServlet.doPost(RegServlet.java:36) javax.servlet.http.HttpServlet.service(HttpServlet.java:648) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) note The full stack trace of the root cause is available in the Apache Tomcat/8.0.21 logs. Apache Tomcat/8.0.21 出现错误场景: 在另外的电脑上测试过是可以正常运行的,但是,换到自己电脑上就出现此类错误,主要原因是Tomcat、mysql-connector-java、jdk几个之间的版本不匹配。 个人推测比较有可能是mysql-connector-java和tomacat版本不匹配,但是不能肯定。(更确切的原因目前也还是不知道) 我最初的配置是: JDK:1.7.0.67 jre1.7 tomcat 8.0.21 mysql-connector-java 5.0.4 解决方法如下: 一、更改了tomcat的版本为apache-tomcat-7.0.64 二、更改mysql-connector-java版本为5.1.24 二者选其一即可。 ps:写入数据库的时候用到了数据连接池,如果不使用数据连接池的话不会有这个问题。
经验分享 程序员 微信小程序 职场和发展