错误:
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.NoClassDefFoundError: com/mchange/v2/c3p0/ComboPooledDataSource
utils.DateSourceUtils.<clinit>(DateSourceUtils.java:13)
severce.TransferService.Transfer(TransferService.java:25)
web.Transfer.doGet(Transfer.java:32)
web.Transfer.doPost(Transfer.java:46)
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)
root cause
java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
utils.DateSourceUtils.<clinit>(DateSourceUtils.java:13)
severce.TransferService.Transfer(TransferService.java:25)
web.Transfer.doGet(Transfer.java:32)
web.Transfer.doPost(Transfer.java:46)
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.5.9 logs.
jsp表单提交
<body>
<form action="Transfer" method="post">
请输入您的用户:<input type="text" name="outname"><br>
请输您要转的用户:<input type="text" name="inname"><br>
请输入您的转账金额:<input type="text" name="money"><br>
<input type="submit" value="确认转账">
</form>
</body>
在web层servlet代码
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String inname=request.getParameter("inname");
String outname=request.getParameter("outname");
String moneystr=request.getParameter("money");
double money=Double.parseDouble(moneystr);
TransferService Service=new TransferService();
boolean cs=Service.Transfer(inname,outname,money);
if(cs){
response.getWriter().write("转账成功");
System.out.println("转账成功");
}else{
response.getWriter().write("转账失败!!!");
System.out.println("转账失败");
}
}
在service层代码
public class TransferService {
public boolean Transfer(String inname, String outname, double money) {
Transferdao dao=new Transferdao();
boolean cs=true;
try {
Connection conn=DateSourceUtils.getConnection();
dao.in(inname,money,conn);
dao.out(outname,money,conn);
} catch (SQLException e) {
cs=false;
e.printStackTrace();
}
return cs;
}
在dao层代码
public class Transferdao{
public void out(String outname, double money,Connection conn) throws SQLException {
QueryRunner runner=new QueryRunner();
String sql="update user set price=price-money where pname=outname";
runner.update(conn, sql);
}
public void in(String inname, double money,Connection conn) throws SQLException {
QueryRunner runner=new QueryRunner();
String sql="update user set price=price+money where pname=inname";
runner.update(conn,sql);
}
java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource
你的连接池的lib包,没有放到你的应用里
无法加载到这个类,看看你是否导入了,或者添加到build path了没有
java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource