有几个问题
商城登录的账号密码是自己设置的吗?是要自己提前建立数据库吗
我建立 了数据库但,提交后台的时候用了正确的账号密码还是报错,
为什么我的账号显示不出来只能显示null,导入项目的mysql是5x版本
null 123
9月 29, 2020 1:30:11 下午 com.mchange.v2.log.MLog <clinit>
信息: MLog clients using java 1.4+ standard logging.
9月 29, 2020 1:30:11 下午 com.mchange.v2.c3p0.C3P0Registry banner
信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
9月 29, 2020 1:30:11 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 2rz1amac1o0yfqx1l2f2yz|555e2372, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 2rz1amac1o0yfqx1l2f2yz|555e2372, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql:///shop?useUnicode=true&characterEncoding=utf8
&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=UTC, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {password=******, user=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
9月 29, 2020 1:30:40 下午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@556dae4 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: Java does not support the MySQL character encoding encoding 'utf8
'.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.Connection.configureCharsetProperties(Connection.java:2294)
at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2335)
at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3913)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2683)
at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
9月 29, 2020 1:30:40 下午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4a47371a -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: Java does not support the MySQL character encoding encoding 'utf8
'.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.Connection.configureCharsetProperties(Connection.java:2294)
at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2335)
at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3913)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2683)
at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
9月 29, 2020 1:30:40 下午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1b363118 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: Java does not support the MySQL character encoding encoding 'utf8
'.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.Connection.configureCharsetProperties(Connection.java:2294)
at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2335)
at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3913)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2683)
at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at com.imooc.utils.JDBCUtils.getConnection(JDBCUtils.java:24)
at com.imooc.dao.impl.UserDaoImpl.login(UserDaoImpl.java:19)
at com.imooc.service.impl.UserServiceImpl.login(UserServiceImpl.java:14)
at com.imooc.web.action.UserServlet.login(UserServlet.java:61)
at com.imooc.web.action.UserServlet.doGet(UserServlet.java:30)
at com.imooc.web.action.UserServlet.doPost(UserServlet.java:77)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 31 more
正在回答 回答被采纳积分+1
您好您看下这个代码有什么问题吗,我看了好久没找到什么问题
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>欢迎使用油画商城</title>
<meta name="keywords" content="HTML5 Bootstrap 3 Admin Template UI Theme" />
<meta name="description" content="AbsoluteAdmin - A Responsive HTML5 Admin UI Framework">
<meta name="author" content="AbsoluteAdmin">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/assets/skin/default_skin/css/theme.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/assets/admin-tools/admin-forms/css/admin-forms.css">
<link rel="shortcut icon" href="${pageContext.request.contextPath }/assets/img/favicon.ico">
</head>
<body class="external-page external-alt sb-l-c sb-r-c">
<div id="main" class="animated fadeIn">
<section id="content_wrapper">
<section id="content">
<div class="admin-form theme-info mw500" id="login">
<div class="content-header">
<h1>油画商城</h1>
<p class="lead">欢迎使用油画商城自动化管理系统</p>
<font color="red">${msg }</font>
</div>
<div class="panel mt30 mb25">
<form method="post" action="${pageContext.request.contextPath}/UserServlet" id="contact">
<input type="hidden" name="method" value="login">
<div class="panel-body bg-light p25 pb15">
<div class="section">
<label for="sn" class="field-label text-muted fs18 mb10">名称</label>
<label for="sn" class="field prepend-icon">
<input type="text" name="usernaame" id="username" class="gui-input" placeholder="请输入名称...">
<label for="password" class="field-icon">
<i class="fa fa-user"></i>
</label>
</label>
</div>
<div class="section">
<label for="password" class="field-label text-muted fs18 mb10">密码</label>
<label for="password" class="field prepend-icon">
<input type="password" name="password" id="password" class="gui-input" placeholder="请输入密码...">
<label for="password" class="field-icon">
<i class="fa fa-lock"></i>
</label>
</label>
</div>
</div>
<div class="panel-footer clearfix text-center">
<button type="submit" class="button btn-primary mr10"> 登陆 </button>
</div>
</form>
</div>
</div>
</section>
</section>
</div>
<script src="vendor/jquery/jquery-1.11.1.min.js"></script>
<script src="vendor/jquery/jquery_ui/jquery-ui.min.js"></script>
<script src="assets/js/utility/utility.js"></script>
<script src="assets/js/demo/demo.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>
package com.imooc.web.action;
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 com.imooc.domain.User;
import com.imooc.service.UserService;
import com.imooc.service.impl.UserServiceImpl;
/**
* Servlet implementation class UserServlet
*/
@WebServlet("/UserServlet")
public class UserServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//接受参数
String methodName=request.getParameter("method");
//判断
if("login".equals(methodName)) {
login(request,response);
}else if("logout".equals(methodName)){
logout(request,response);
}
}
//用户退出的方法
private void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
//1.将session销毁
request.getSession().invalidate();
//2.页面进行跳转,跳转到登陆页面
response.sendRedirect(request.getContextPath()+"/admin/login.jsp");
}
/**
* UserServlet登录的方法
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
private void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//接收用户名和密码
String username=request.getParameter("username");
String password=request.getParameter("password");
System.out.println(username+" "+password);
User user=new User();
user.setUsername(username);
user.setPassword(password);
//处理数据
UserService userService=new UserServiceImpl();
User existUser=userService.login(user);
//根据处理结果完成页面跳转
if(existUser==null) {
//登录失败
//返回到登录页面
request.setAttribute("msg","用户名和密码错误!");
request.getRequestDispatcher("/admin/login.jsp").forward(request,response);
}else {
//登录成功
//将用户的信息进行保存,进行页面跳转
request.getSession().setAttribute("existUser",existUser);
response.sendRedirect(request.getContextPath()+"/admin/category_list.jsp");
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
}
package com.imooc.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.imooc.dao.UserDao;
import com.imooc.domain.User;
import com.imooc.utils.JDBCUtils;
public class UserDaoImpl implements UserDao {
@Override
public User login(User user) {
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
try {
//获得连接
conn=JDBCUtils.getConnection();
//编写sql
String sql="select*from user where username=? and password=?";
//预编译sql
pstmt=conn.prepareStatement(sql);
//设置参数
pstmt.setString(1,user.getUsername());
pstmt.setString(2,user.getPassword());
//执行
rs=pstmt.executeQuery();
if(rs.next()) {
User existuser=new User();
existuser.setPassword(rs.getString("password"));
existuser.setUsername(rs.getString("username"));
existuser.setUid(rs.getInt("uid"));
return existuser;
}
}catch(Exception e){
e.printStackTrace();
}finally{
//释放资源
JDBCUtils.release(rs, pstmt, conn);
}
return null;
}
}
package com.imooc.domain;
public class User {
private String username;
private String password;
private int uid;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
}
同学你好,
1、商城登录的账号密码是自己设置的吗?是要自己提前建立数据库吗
1)账号密码是在数据库表中添加,这里同学可以手动添加呐
2)是需要提前建立数据库的,以及需要用的表。
注:这里同学可以下载教辅区的资料,找到sql文件导入即可
2、我建立了数据库但,提交后台的时候用了正确的账号密码还是报错
这里具体的报错信息是什么呢?建议同学将错误信息贴出。
3、为什么我的账号显示不出来只能显示null,导入项目的mysql是5x版本
账号显示为null,说明没有成功接收到项目名,建议同学输入账号密码时打开浏览器控制台查看username是否正确传递呢?如下:
4、请问你贴出的错误信息,是一次报了这集中错误吗?还是你将多次报的错误都贴出来了。
看同学的错误,每个错误都是不同的原因。
1)根据报错信息:java不支持mysql字符编码“utf8”
修改建议:找到mysql的my.ini文件,在如下位置处设置字符集
2)根据如下报错:同学是mysql8还是mysql5 呢,如果是mysql8,驱动配置这里应更改为
com.mysql.cj.jdbc.Driver
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星