软件系统开发定制用 JSP 连接 MySQL 登入注册项目实践(JSP + HTML + CSS + MySQL)

目录 


相关文章

jsp软件系统开发定制实现简单登入注册界面功能
JDBC 连接 MySQL

一、写在前面

       哈喽~大家好,软件系统开发定制这篇呢我们来看看用 JSP 连接 MySQL 软件系统开发定制登入注册项目实践,软件系统开发定制这里就可能有人问了,唉?追桑~软件系统开发定制前些天不是写了 jsp 软件系统开发定制登入注册的项目吗?软件系统开发定制怎么这次还在写呢?哈哈,您别担心,这次呢,软件系统开发定制肯定和上次不同,我们先来看看效果吧!

二、效果图

数据库界面

感觉是不是不一样了,哈哈哈,那么接下来我们来看看是怎么实现的。

三、实现思路

首先我们这里很明显,有四个总页面分别是 login(登入界面)、logout(注销界面)、amend(修改界面)、register(注册界面),这四个总页面分别对应着检查页面(check)、成功页面(success)、失败页面(fail)。建立之好后,通过 from 的 action 来进行跳转,我们先来看看 MySQL (数据库)表名叫 login。

我们这里数据库共三列,第一列叫 name (用户名)、pass(密码)、time(注册时间),name 与 pass 都是 int(整型) 类型的,time 是 varchar (可变长类型),如图。

四、实现代码

1、login总界面

首先我们先有个页面,有基本的用户名框,密码框,两按钮,一个注册,一个注销,通过 from进行跳转,代码如下

  1. <form method="post" action="check.jsp">
  2. <input type="text" name="user" style="width: 300px;height: 50px" placeholder="请输入用户名:"
  3. > <br>
  4. <input type="password" name="pass" style="width: 300px;height: 50px" placeholder="请输入密码:" > <br>
  5. <button type="submit" style="width:80px;height:40px; font-size: 20px" class="clear">登录</button>
  6. <button type="reset" style="width:80px;height:40px; font-size: 20px" class="clear">重置</button>
  7. <br>
  8. 没有账号?<a href="register.jsp">点击注册</a><br>
  9. 不想用了?<a href="logout.jsp">点击注销</a>
  10. </form>

用 check 连接数据库(如何连接数据库,前面文章已经给出了,有兴趣的小伙伴可以看看前面写的文章,也放在前面了) 同样的道理,还是那五个步骤(这里就不过多的解释,可以看看上面表格给出的文章),先来看看代码。

  1. String user = request.getParameter("user"); // getParameter 与 getAttribute 区别
  2. String pass = request.getParameter("pass");
  3. // String getParameter(String name):根据参数名称获取参数值
  4. // getAttribute()获取的是服务器设置的数据。getAttribute() 方法返回指定属性名的属性值。
  5. try {
  6. Class.forName("com.mysql.cj.jdbc.Driver");
  7. String url = "jdbc:mysql://localhost:3306/db1?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC";
  8. String user1 = "root";
  9. String pass1 = "123456";
  10. Connection connection = DriverManager.getConnection(url,user1,pass1);
  11. String sql = "select * from login where name=? and pass=?";
  12. PreparedStatement ps = connection.prepareStatement(sql);
  13. ps.setString(1,user);
  14. ps.setString(2,pass);
  15. ResultSet re = ps.executeQuery();
  16. if (re.next()){
  17. response.sendRedirect("loginsuccess.jsp");
  18. session.setAttribute("user",user);
  19. }else {
  20. response.sendRedirect("loginfail.jsp");
  21. }
  22. } catch (ClassNotFoundException e) {
  23. e.printStackTrace();
  24. } catch (SQLException e) {
  25. e.printStackTrace();
  26. }

这里 response. 跳转了两个页面一个 loginsuccess 和 loginfail 的两个界面,下面我们来看看,这两个文件(其实很简单)

loginsuccess 代码

  1. <div class="form">
  2. <h2> <h22>登录成功</h22><br>
  3. </h2>
  4. <fon>恭喜您成功登入 <br> &nbsp;&nbsp; 欢迎使用 <br>
  5. <a class="a1" href="login.jsp">返回登入界面</a>
  6. </fon>
  7. </div>

loginfail 代码:

  1. <h2> <h22>登录失败</h22><br>
  2. </h2>
  3. <fon>宝~是不是账号或密码记错惹? <br>
  4. <a class="a1" href="login.jsp">返回登入界面</a><br>
  5. <p1><a href="amend.jsp">点击修改密码</a></p1>
  6. </fon>

这里我们点击运行看看效果

这里我们用两个升级 大装备(html)(css) 来美化一下我们的页面,这里我们页面美化的,用的是这位大佬的页面(博主名为键盘奏鸣曲),大家可以来看看,

HTML 代码

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <head>
  3. <meta charset="UTF-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  5. <link rel="stylesheet" href="css.css">
  6. <title>123</title>
  7. </head>
  8. <body>
  9. <section>
  10. <div class="color"></div>
  11. <div class="color"></div>
  12. <div class="color"></div>
  13. <div class="box">
  14. <div class="circle" style="--x:0"></div>
  15. <div class="circle" style="--x:1"></div>
  16. <div class="circle" style="--x:2"></div>
  17. <div class="circle" style="--x:3"></div>
  18. <div class="circle" style="--x:4"></div>
  19. <div class="container">
  20. <div class="form">
  21. <h2>登录</h2>
  22. <form method="post" action="check.jsp">
  23. <div class="inputBox">
  24. <input type="text" placeholder="姓名" name="user">
  25. </div>
  26. <div class="inputBox">
  27. <input type="password" placeholder="密码" name="pass">
  28. </div>
  29. <div class="inputBox">
  30. <input type="submit" value="登录">
  31. </div>
  32. <p class="forget">不想用了?<a href="logout.jsp">
  33. 点击这里
  34. </a></p>
  35. <p class="forget">没有账户?<a href="register.jsp">
  36. 注册
  37. </a></p>
  38. </form>
  39. </div>
  40. </div>
  41. </div>
  42. </section>
  43. </body>
  44. </html>

 CSS 代码

  1. /*.center{*/
  2. /* text-align:center;*/
  3. /* margin-top: 50px;*/
  4. /*}*/
  5. .fon{
  6. font-size: 40px;
  7. }
  8. /*body{*/
  9. /* background: url("images/image-2.jpg") no-repeat 0 0;*/
  10. /* background-size: 100% 100%;*/
  11. /* text-decoration:none;*/
  12. /*}*/
  13. /*input {*/
  14. /* background-color: transparent;*/
  15. /* outline: none;*/
  16. /* color: black;*/
  17. /*}*/
  18. /*.clear{*/
  19. /* opacity:0.3;*/
  20. /*}*/
  21. * {
  22. margin: 0;
  23. padding: 0;
  24. box-sizing: border-box;
  25. }
  26. /* 使用flex布局,让内容垂直和水平居中 */
  27. section {
  28. /* 相对定位 */
  29. position: relative;
  30. overflow: hidden;
  31. display: flex;
  32. justify-content: center;
  33. align-items: center;
  34. min-height: 100vh;
  35. /* linear-gradient() 函数用于创建一个表示两种或多种颜色线性渐变的图片 */
  36. background: linear-gradient(to bottom, #f1f4f9, #dff1ff);
  37. }
  38. /* 背景颜色 */
  39. section .color {
  40. /* 绝对定位 */
  41. position: absolute;
  42. /* 使用filter(滤镜) 属性,给图像设置高斯模糊*/
  43. filter: blur(200px);
  44. }
  45. /* :nth-child(n) 选择器匹配父元素中的第 n 个子元素 */
  46. section .color:nth-child(1) {
  47. top: -350px;
  48. width: 600px;
  49. height: 600px;
  50. background: #ff359b;
  51. }
  52. section .color:nth-child(2) {
  53. bottom: -150px;
  54. left: 100px;
  55. width: 500px;
  56. height: 500px;
  57. background: #fffd87;
  58. }
  59. section .color:nth-child(3) {
  60. bottom: 50px;
  61. right: 100px;
  62. width: 500px;
  63. height: 500px;
  64. background: #00d2ff;
  65. }
  66. .box {
  67. position: relative;
  68. }
  69. /* 背景圆样式 */
  70. .box .circle {
  71. position: absolute;
  72. background: rgba(255, 255, 255, 0.1);
  73. /* backdrop-filter属性为一个元素后面区域添加模糊效果 */
  74. backdrop-filter: blur(5px);
  75. box-shadow: 0 25px 45px rgba(0, 0, 0, 0.1);
  76. border: 1px solid rgba(255, 255, 255, 0.5);
  77. border-right: 1px solid rgba(255, 255, 255, 0.2);
  78. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  79. border-radius: 50%;
  80. /* 使用filter(滤镜) 属性,改变颜色。
  81. hue-rotate(deg) 给图像应用色相旋转
  82. calc() 函数用于动态计算长度值
  83. var() 函数调用自定义的CSS属性值x*/
  84. filter: hue-rotate(calc(var(--x) * 70deg));
  85. /* 调用动画animate,需要10s完成动画,
  86. linear表示动画从头到尾的速度是相同的,
  87. infinite指定动画应该循环播放无限次*/
  88. animation: animate 10s linear infinite;
  89. /* 动态计算动画延迟几秒播放 */
  90. animation-delay: calc(var(--x) * -1s);
  91. }
  92. /* 背景圆动画 */
  93. @keyframes animate {
  94. 0%, 100% {
  95. transform: translateY(-50px);
  96. }
  97. 50% {
  98. transform: translateY(50px);
  99. }
  100. }
  101. .box .circle:nth-child(1) {
  102. top: -50px;
  103. right: -60px;
  104. width: 100px;
  105. height: 100px;
  106. }
  107. .box .circle:nth-child(2) {
  108. top: 150px;
  109. left: -100px;
  110. width: 120px;
  111. height: 120px;
  112. z-index: 2;
  113. }
  114. .box .circle:nth-child(3) {
  115. bottom: 50px;
  116. right: -60px;
  117. width: 80px;
  118. height: 80px;
  119. z-index: 2;
  120. }
  121. .box .circle:nth-child(4) {
  122. bottom: -80px;
  123. left: 100px;
  124. width: 60px;
  125. height: 60px;
  126. }
  127. .box .circle:nth-child(5) {
  128. top: -80px;
  129. left: 140px;
  130. width: 60px;
  131. height: 60px;
  132. }
  133. /* 登录框样式 */
  134. .container {
  135. position: relative;
  136. width: 400px;
  137. min-height: 400px;
  138. background: rgba(255, 255, 255, 0.1);
  139. display: flex;
  140. justify-content: center;
  141. align-items: center;
  142. backdrop-filter: blur(5px);
  143. box-shadow: 0 25px 45px rgba(0, 0, 0, 0.1);
  144. border: 1px solid rgba(255, 255, 255, 0.5);
  145. border-right: 1px solid rgba(255, 255, 255, 0.2);
  146. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  147. }
  148. .form {
  149. position: relative;
  150. width: 100%;
  151. height: 100%;
  152. padding: 50px;
  153. }
  154. /* 登录标题样式 */
  155. .form h2 {
  156. text-align: center;
  157. position: relative;
  158. color: #fff;
  159. font-size: 40px;
  160. font-weight: 600;
  161. letter-spacing: 5px;
  162. margin-bottom: 30px;
  163. cursor: pointer;
  164. }
  165. .form h2 h22 {
  166. top: -40px;
  167. text-align: center;
  168. position: relative;
  169. color: #fff;
  170. font-size: 40px;
  171. font-weight: 600;
  172. letter-spacing: 5px;
  173. margin-bottom: 30px;
  174. cursor: pointer;
  175. }
  176. .form .a1, .form p1 {
  177. bottom: -90px;
  178. left: 50px;
  179. position: relative;
  180. color: #fff;
  181. font-size: 18px;
  182. font-weight: 600;
  183. letter-spacing: 5px;
  184. /*margin-bottom: 10px;*/
  185. cursor: pointer;
  186. text-decoration: none;
  187. }
  188. .form p1 a{
  189. position: relative;
  190. color: #fff;
  191. font-size: 18px;
  192. font-weight: 600;
  193. letter-spacing: 5px;
  194. /*margin-bottom: 10px;*/
  195. cursor: pointer;
  196. text-decoration: none;
  197. }
  198. .form fon {
  199. top: -30px;
  200. left: 30px;
  201. position: relative;
  202. color: #fff;
  203. font-size: 28px;
  204. font-weight: 600;
  205. letter-spacing: 5px;
  206. margin-bottom: 30px;
  207. cursor: pointer;
  208. }
  209. /* 登录标题的下划线样式 */
  210. .form h2::before {
  211. content: "";
  212. position: absolute;
  213. left: 0;
  214. bottom: -10px;
  215. width: 0px;
  216. height: 3px;
  217. background: #fff;
  218. transition: 0.5s;
  219. }
  220. .form h2 h22::before {
  221. content: "";
  222. position: absolute;
  223. /*left: 0;*/
  224. /*bottom: -10px;*/
  225. /*width: 0px;*/
  226. /*height: 3px;*/
  227. /*background: #fff;*/
  228. /*transition: 0.5s;*/
  229. }
  230. .form h2:hover:before {
  231. width: 53px;
  232. }
  233. .form .inputBox {
  234. width: 100%;
  235. margin-top: 20px;
  236. }
  237. /* 输入框样式 */
  238. .form .inputBox input {
  239. width: 100%;
  240. padding: 10px 20px;
  241. background: rgba(255, 255, 255, 0.2);
  242. outline: none;
  243. border: none;
  244. border-radius: 30px;
  245. border: 1px solid rgba(255, 255, 255, 0.5);
  246. border-right: 1px solid rgba(255, 255, 255, 0.2);
  247. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  248. font-size: 16px;
  249. letter-spacing: 1px;
  250. color: #fff;
  251. box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
  252. }
  253. .form .inputBox input::placeholder {
  254. color: #fff;
  255. }
  256. /* 登录按钮样式 */
  257. .form .inputBox input[type="submit"],.form .inputBox input[type="reset"] {
  258. background: #fff;
  259. color: #666;
  260. max-width: 100%;
  261. margin-bottom: 20px;
  262. font-weight: 600;
  263. cursor: pointer;
  264. }
  265. .forget {
  266. margin-top: 6px;
  267. color: #fff;
  268. letter-spacing: 1px;
  269. }
  270. .forget a {
  271. color: #fff;
  272. font-weight: 600;
  273. text-decoration: none;
  274. }

同样的道理我们来升级一下 loginsuccess 与 loginfail 。

loginsuccess 代码

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <html>
  3. <head>
  4. <title>登入成功界面</title>
  5. <link rel="stylesheet" href="css.css" type="text/css">
  6. </head>
  7. <body>
  8. <%--<div class="center">--%>
  9. <%-- <p class="fon">登入成功界面</p>--%>
  10. <%-- <p class="fon1">恭喜您成功登入,欢迎使用</p>--%>
  11. <%-- <a href="login.jsp">点击退出,返回登入界面</a>--%>
  12. <%--</div>--%>
  13. <section>
  14. <div class="color"></div>
  15. <div class="color"></div>
  16. <div class="color"></div>
  17. <div class="box">
  18. <div class="circle" style="--x:0"></div>
  19. <div class="circle" style="--x:1"></div>
  20. <div class="circle" style="--x:2"></div>
  21. <div class="circle" style="--x:3"></div>
  22. <div class="circle" style="--x:4"></div>
  23. <div class="container">
  24. <div class="form">
  25. <h2> <h22>登录成功</h22><br>
  26. </h2>
  27. <fon>恭喜您成功登入 <br> &nbsp;&nbsp; 欢迎使用 <br>
  28. <a class="a1" href="login.jsp">返回登入界面</a>
  29. </fon>
  30. </div>
  31. </div>
  32. </div>
  33. </section>
  34. </body>
  35. </html>

loginfail 代码

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <html>
  3. <head>
  4. <title>登入失败界面</title>
  5. <link rel="stylesheet" href="css.css" type="text/css">
  6. </head>
  7. <body>
  8. <%--<div class="center">--%>
  9. <%-- <p class="fon">登入失败界面</p>--%>
  10. <%-- <p class="fon1">对不起,您账号或密码有误,请返回登入界面</p>--%>
  11. <%-- <a href="login.jsp">返回登入界面</a><br>--%>
  12. <%-- 忘记密码?<a href="amend.jsp">点击修改密码</a>--%>
  13. <%--</div>--%>
  14. <section>
  15. <div class="color"></div>
  16. <div class="color"></div>
  17. <div class="color"></div>
  18. <div class="box">
  19. <div class="circle" style="--x:0"></div>
  20. <div class="circle" style="--x:1"></div>
  21. <div class="circle" style="--x:2"></div>
  22. <div class="circle" style="--x:3"></div>
  23. <div class="circle" style="--x:4"></div>
  24. <div class="container">
  25. <div class="form">
  26. <h2> <h22>登录失败</h22><br>
  27. </h2>
  28. <fon>宝~是不是账号或密码记错惹? <br>
  29. <a class="a1" href="login.jsp">返回登入界面</a><br>
  30. <p1><a href="amend.jsp">点击修改密码</a></p1>
  31. </fon>
  32. </div>
  33. </div>
  34. </div>
  35. </section>
  36. </body>
  37. </html>

点击运行,我们来看看效果

 那么这里我们是完成了,login总界面的效果,同样的道理,代码都差不多,我们直接 cv 大法,这里就给出重点要改的代码。

2、registercheck总代码

里面要重点改的代码,一个是 sql 语句插入,另一个是。

String sql = "insert into login(name, pass,time)VALUES(?,?,?)";
  1. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 时间转换,要不然就会是国际时间格式
  2. String data = formatter.format(new Date());// 记录的是当前的时间
  3. ps.setString(3,data);

3、logoutcheck总代码

里面要重点改的代码,是 sql 语句删除。

String sql = "DELETE FROM login WHERE name =? and pass =?";

4、amendcheck总代码

里面要重点改的代码,是 sql 语句更新。

String sql = "update login set pass='"+pass+"'";

然后分别是各个总页面的 success 与 fail 页面来实现好,这里有一个小细节,我们在作抛出异常,这里可以 out.println 来打印出信息来测试,可以输出在网页上,这样可以方便知道那里有异常。

  1. catch (ClassNotFoundException e) {
  2. e.printStackTrace();
  3. out.println("1");
  4. // response.sendRedirect("registerfail.jsp");
  5. } catch (SQLException e) {
  6. e.printStackTrace();
  7. out.println("2");
  8. // response.sendRedirect("registerfail.jsp");
  9. }

 好了,点击运行,完成总效果。

(求关注)持续更新中…… 

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发