有几个问题

有几个问题

  1. 商城登录的账号密码是自己设置的吗?是要自己提前建立数据库吗

  2. 我建立 了数据库但,提交后台的时候用了正确的账号密码还是报错,

  3. 为什么我的账号显示不出来只能显示null,导入项目的mysql是5x版本

  4. null 123

  5. 9月 29, 2020 1:30:11 下午 com.mchange.v2.log.MLog <clinit>

  6. 信息: MLog clients using java 1.4+ standard logging.

  7. 9月 29, 2020 1:30:11 下午 com.mchange.v2.c3p0.C3P0Registry banner

  8. 信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]

  9. 9月 29, 2020 1:30:11 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager

  10. 信息: 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

  11. &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 ]

  12. 9月 29, 2020 1:30:40 下午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run

  13. 警告: 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: 

  14. java.sql.SQLException: Java does not support the MySQL character encoding  encoding 'utf8

  15. '.

  16. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)

  17. at com.mysql.jdbc.Connection.configureCharsetProperties(Connection.java:2294)

  18. at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2335)

  19. at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3913)

  20. at com.mysql.jdbc.Connection.createNewIO(Connection.java:2683)

  21. at com.mysql.jdbc.Connection.<init>(Connection.java:1531)

  22. at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)

  23. at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)

  24. at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

  25. at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

  26. at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

  27. at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

  28. at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

  29. at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

  30. at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)


  31. 9月 29, 2020 1:30:40 下午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run

  32. 警告: 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: 

  33. java.sql.SQLException: Java does not support the MySQL character encoding  encoding 'utf8

  34. '.

  35. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)

  36. at com.mysql.jdbc.Connection.configureCharsetProperties(Connection.java:2294)

  37. at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2335)

  38. at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3913)

  39. at com.mysql.jdbc.Connection.createNewIO(Connection.java:2683)

  40. at com.mysql.jdbc.Connection.<init>(Connection.java:1531)

  41. at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)

  42. at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)

  43. at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

  44. at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

  45. at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

  46. at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

  47. at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

  48. at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

  49. at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)


  50. 9月 29, 2020 1:30:40 下午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run

  51. 警告: 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: 

  52. java.sql.SQLException: Java does not support the MySQL character encoding  encoding 'utf8

  53. '.

  54. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)

  55. at com.mysql.jdbc.Connection.configureCharsetProperties(Connection.java:2294)

  56. at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2335)

  57. at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3913)

  58. at com.mysql.jdbc.Connection.createNewIO(Connection.java:2683)

  59. at com.mysql.jdbc.Connection.<init>(Connection.java:1531)

  60. at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)

  61. at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)

  62. at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

  63. at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

  64. at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

  65. at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

  66. at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

  67. at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

  68. at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)


  69. java.sql.SQLException: Connections could not be acquired from the underlying database!

  70. at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)

  71. at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)

  72. at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)

  73. at com.imooc.utils.JDBCUtils.getConnection(JDBCUtils.java:24)

  74. at com.imooc.dao.impl.UserDaoImpl.login(UserDaoImpl.java:19)

  75. at com.imooc.service.impl.UserServiceImpl.login(UserServiceImpl.java:14)

  76. at com.imooc.web.action.UserServlet.login(UserServlet.java:61)

  77. at com.imooc.web.action.UserServlet.doGet(UserServlet.java:30)

  78. at com.imooc.web.action.UserServlet.doPost(UserServlet.java:77)

  79. at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)

  80. at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)

  81. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

  82. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

  83. at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

  84. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

  85. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

  86. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)

  87. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)

  88. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)

  89. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)

  90. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)

  91. at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)

  92. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)

  93. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)

  94. at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)

  95. at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)

  96. at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)

  97. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)

  98. at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

  99. at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)

  100. at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)

  101. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

  102. at java.base/java.lang.Thread.run(Thread.java:832)

  103. Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.

  104. at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)

  105. at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)

  106. at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)

  107. at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)

  108. ... 31 more

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

6回答
好帮手慕小班 2020-09-30 11:04:01

同学你好,测试同学贴出的代码,在页面中,同学username单词书写有误,导致在Servlet中没有正确获取到用户名内容,比如:

在页面中,name为usernaame

http://img1.sycdn.imooc.com//climg/5f73f54e09b9cbfc07200196.jpg

而在Servlet中却是username

http://img1.sycdn.imooc.com//climg/5f73f58009edd05d05410178.jpg

所以用户名获取不到,建议同学将页面中usernaame修改为username。

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

提问者 怀夢 2020-09-30 08:56:09

您好您看下这个代码有什么问题吗,我看了好久没找到什么问题

<%@ 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;

}


}


好帮手慕小脸 2020-09-29 19:00:07

同学你好,

1、这里是下载课程中的资料,然后将sql文件导入到数据库中,当然同学这里手动创建数据库,表等也是可以的

2、猜测同学获取的key与前台传的key不一样,建议同学检查一下单词是否书写错误,大小写是否正确区分呢?如果未解决,建议将这部分代码贴出,方便老师解决问题

祝学习愉快~


  • 提问者 怀夢 #1
    数据库中文显示乱码怎么解决呢,
    2020-09-30 10:50:28
  • 提问者 怀夢 #2
    这个我也解决了,只有不知道为什么username显示null无法进行下一步这个问题
    2020-09-30 10:56:36
提问者 怀夢 2020-09-29 16:46:32

现在其他问题我自行解决了。就是回传数据的时候为什么我的username 不管我输入什么都显示null哎,password都是正常的

好帮手慕小脸 2020-09-29 16:42:17

同学你好,

1、商城登录的账号密码是自己设置的吗?是要自己提前建立数据库吗

1)账号密码是在数据库表中添加,这里同学可以手动添加呐

2)是需要提前建立数据库的,以及需要用的表。

注:这里同学可以下载教辅区的资料,找到sql文件导入即可

http://img1.sycdn.imooc.com//climg/5f72e8690978d9ed03960276.jpg


2、我建立了数据库但,提交后台的时候用了正确的账号密码还是报错

这里具体的报错信息是什么呢?建议同学将错误信息贴出。

3、为什么我的账号显示不出来只能显示null,导入项目的mysql是5x版本

账号显示为null,说明没有成功接收到项目名,建议同学输入账号密码时打开浏览器控制台查看username是否正确传递呢?如下:

http://img1.sycdn.imooc.com//climg/5f72ec3e09ff271c12790761.jpg

4、请问你贴出的错误信息,是一次报了这集中错误吗?还是你将多次报的错误都贴出来了。

看同学的错误,每个错误都是不同的原因。

    1)根据报错信息:java不支持mysql字符编码“utf8”

http://img1.sycdn.imooc.com//climg/5f72ece4099bb72c07780149.jpg

修改建议:找到mysql的my.ini文件,在如下位置处设置字符集

http://img1.sycdn.imooc.com//climg/5f72f34d09c0744406280349.jpg

    2)根据如下报错:同学是mysql8还是mysql5 呢,如果是mysql8,驱动配置这里应更改为

com.mysql.cj.jdbc.Driver

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

  • 提问者 怀夢 #1
    还有就是您说的从资料钟导入sql是导入到哪里哎?直接导入到eclipse还是数据库包下呢,我数据库,表,内容都是自己创建的,username显示null这个真的没搞懂,别的问题都解决了现在只有username显示null
    2020-09-29 16:50:55
  • 提问者 怀夢 #2
    控制台中可以看到username的回传值
    2020-09-29 16:59:37
提问者 怀夢 2020-09-29 13:34:58

只会显示一个密码,我特意因为这个买了个服务,到期了,麻烦帮我详细点解答下,我百度了半天找不到对应答案,方法也试了好多

  • 提问者 怀夢 #1
    数据库是8.0的版本
    2020-09-29 13:38:42
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师