主要知识点:jsp指令标记、动作标记、内置对象request、response、session等的使用。
直接上代码:
login.jsp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| <%-- Created by IntelliJ IDEA. User: 刘方涵 Date: 2019/9/22 Time: 17:24 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>登录</title> <link rel="stylesheet" href="login.css"> </head> <body> <div class="main"> <h1>登录</h1> <form action="judge.jsp" method="post"> <p>账号</p> <input type="text" name="account" /> <p>密码</p> <input type="password" name="password" /> <input type="submit" value="提交" > <a href="../register/register.jsp"> <input type="button" value="注册"> </a> </form> </div> <% request.setCharacterEncoding("utf-8"); String account = request.getParameter("account"); String password = request.getParameter("password");
if (account == null) { account = ""; } if (password == null) { password = ""; }
%> </body> </html>
|
judge.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <%-- Created by IntelliJ IDEA. User: 刘方涵 Date: 2019/9/22 Time: 17:35 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>判定</title> </head> <body> <% request.setCharacterEncoding("utf-8"); String account = request.getParameter("account"); String password = request.getParameter("password"); if (account.equals("") || password.equals("")) { request.setCharacterEncoding("gb2312");
session.setAttribute("msg", "请将所有信息填写完整"); response.sendRedirect("../error/error.jsp"); } else { if (account.equals(session.getAttribute("account")) && password.equals(session.getAttribute("password"))) { response.sendRedirect("../../Q3/shop.jsp"); } else { session.setAttribute("msg", "账号或密码错误,请重新输入"); response.sendRedirect("../error/error.jsp"); } } %> </body> </html>
|
login.css:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| body { margin: 0; padding: 0; background: url("B1.jpg"); background-size: cover;
}
.main { width: 350px; height: 400px; margin: 0 auto; padding: 40px; padding-top: 20px; background: rgba(0, 0, 0, .5); border-radius: 10px; margin-top: 80px; color: white; box-shadow: rgba(0, 0, 0, .5) 0 0 5px 5px; }
input[type=text], input[type=password] { background: transparent; border-style: solid; border-width: 2px; border-color: darkslateblue; width: 100%; height: 42px; border-radius: 5px; font-size: 20px; outline: none; padding-left: 10px; }
p { margin-bottom: 10px; }
input[type=submit], input[type=button] { margin-top: 30px; border: 0; padding: 0; width: 100px; height: 35px; color: white; border-radius: 5px; outline: none; margin-right: 10px; }
input[type=submit] { background: limegreen; }
input[type=button] { background: red; }
|
register.jsp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| <%-- Created by IntelliJ IDEA. User: 刘方涵 Date: 2019/9/22 Time: 19:47 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>注册</title> <link rel="stylesheet" href="../login/login.css"> <style> body { background: url("../login/B3.jpg"); background-size: cover; } </style> </head> <body> <div class="main"> <h1>注册</h1> <form action="judgeNew.jsp" method="post"> <p>账号</p> <input type="text" name="account"/> <p>密码</p> <input type="password" name="password"/> <p>确认密码</p> <input type="password" name="checkPass"/> <input type="submit" value="确定"> </form> </div> <% request.setCharacterEncoding("utf-8"); String account = request.getParameter("account"); String password = request.getParameter("password"); String checkPass = request.getParameter("checkPass"); if (account == null || password == null || checkPass == null) { account = ""; password = ""; checkPass = ""; } %> </body> </html>
|
judgeNew.jsp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| <%-- Created by IntelliJ IDEA. User: 刘方涵 Date: 2019/9/22 Time: 19:54 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>注册判定</title> </head> <body> <% request.setCharacterEncoding("utf-8"); String account = request.getParameter("account"); String password = request.getParameter("password"); String checkPass = request.getParameter("checkPass"); if (account.equals("") || password.equals("") || checkPass.equals("")) { session.setAttribute("msg", "请将所有信息输入完整_"); response.sendRedirect("../error/error.jsp"); } else { if (!password.equals(checkPass)) { session.setAttribute("msg", "两次输入的密码不一致,请重新输入_"); response.sendRedirect("../error/error.jsp"); } else { session.setAttribute("account", account); session.setAttribute("password", password); response.sendRedirect("../success/regSuc.jsp"); } } %> </body> </html>
|
success.jsp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <%-- Created by IntelliJ IDEA. User: 刘方涵 Date: 2019/9/24 Time: 19:03 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>注册成功</title> <link rel="stylesheet" href="../error/error.css"> </head> <body> <% String account = (String) session.getAttribute("account"); String password = (String) session.getAttribute("password"); %> <div class="main"> <h1>注册成功</h1> <p>账号:<%=account%> </p> <p>密码:<%=password%> </p> <a href="../login/login.jsp">去登陆</a> </div> </body> </html>
|
regSuc.jsp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <%-- Created by IntelliJ IDEA. User: 刘方涵 Date: 2019/9/24 Time: 19:03 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>注册成功</title> <link rel="stylesheet" href="../error/error.css"> </head> <body> <% String account = (String) session.getAttribute("account"); String password = (String) session.getAttribute("password"); %> <div class="main"> <h1>注册成功</h1> <p>账号:<%=account%> </p> <p>密码:<%=password%> </p> <a href="../login/login.jsp">去登陆</a> </div> </body> </html>
|
error.jsp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <%-- Created by IntelliJ IDEA. User: 刘方涵 Date: 2019/9/24 Time: 18:27 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>登陆失败</title> <link rel="stylesheet" href="error.css"> </head> <%
String msg = (String) session.getAttribute("msg"); String m = "登录"; if (msg.equals("请将所有信息输入完整_") || msg.equals("两次输入的密码不一致,请重新输入_")) { msg = msg.substring(0, msg.length() - 1); response.setHeader("Refresh", "2;url=../register/register.jsp"); m = "注册"; } else response.setHeader("Refresh", "2;url=../login/login.jsp"); %> <body> <div class="main"> <h1><%=m%>失败!</h1> <p>提示:<%=msg%> </p> <p>2秒后返回<%=m%>页面</p> </div> </body> </html>
|
error.css:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| body{ background: url("error.jpg"); background-size: cover; } .main{ padding: 40px; margin: 0 auto; background: hsla(0,0%,100%,.3); width: 20%; color: black; margin-top: 200px; } h1{ color: red; }
|
shop.jsp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| <%-- Created by IntelliJ IDEA. User: 刘方涵 Date: 2019/9/24 Time: 20:26 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>欢迎</title> <link rel="stylesheet" href="shop.css"> </head> <body> <div class="main"> <% request.setCharacterEncoding("utf-8"); String name = (String) session.getAttribute("account");
%> <div class="msg"> <p> 欢迎你, <span style="color: darkcyan"><%=name%></span> </p> </div>
<form action="shopCar.jsp" method="post"> <ul> <li> <div> <img src="photoImg/1.jpg" alt=""/> <p class="money">¥2499</p> <p>荣耀20 李现同款 4800万超广角AI四摄 3200W美颜自拍 麒麟Kirin980全网通版</p> <button disabled="disabled">是否购买?</button> <input type="checkbox" name="choice" value="2499¥荣耀20 李现同款 4800万超广角AI四摄 3200W美颜自拍 麒麟Kirin980全网通版"/> </div> </li> <li> <div> <img src="photoImg/2.jpg" alt=""/> <p class="money">¥1599</p> <p>荣耀9X 麒麟810 4000mAh超强续航 4800万超清夜拍 6.59英寸升降全面屏</p> <button disabled="disabled">是否购买?</button> <input type="checkbox" name="choice" value="1599¥荣耀9X 麒麟810 4000mAh超强续航 4800万超清夜拍 6.59英寸升降全面屏"/> </div> </li> <li> <div> <img src="photoImg/3.jpg" alt=""/> <p class="money">¥999</p> <p>荣耀8X 千元屏霸 91%屏占比 2000万AI双摄 4GB+64GB 幻夜黑 移动</p> <button disabled="disabled">是否购买?</button> <input type="checkbox" name="choice" value="999¥荣耀8X 千元屏霸 91%屏占比 2000万AI双摄 4GB+64GB 幻夜黑 移动"/> </div> </li> <li> <div> <img src="photoImg/4.jpg" alt=""/> <p class="money">¥999</p> <p>荣耀10青春版 幻彩渐变 2400万AI自拍 全网通版4GB+64GB 渐变蓝 </p> <button disabled="disabled">是否购买?</button> <input type="checkbox" name="choice" value="999¥荣耀10青春版 幻彩渐变 2400万AI自拍 全网通版4GB+64GB 渐变蓝"/> </div> </li> <li> <div> <img src="photoImg/5.jpg" alt=""/> <p class="money">¥3988</p> <p>华为 HUAWEI P30 超感光徕卡三摄麒麟980AI智能芯片全面屏屏内指纹</p> <button disabled="disabled">是否购买?</button> <input type="checkbox" name="choice" value="3988¥华为 HUAWEI P30 超感光徕卡三摄麒麟980AI智能芯片全面屏屏内指纹"/> </div> </li> <li> <div> <img src="photoImg/6.jpg" alt=""/> <p class="money">¥2899</p> <p>荣耀20 PRO 李现同款 4800万全焦段AI四摄 双光学防抖 麒麟980 全网通4G </p> <button disabled="disabled">是否购买?</button> <input type="checkbox" name="choice" value="2899¥荣耀20 PRO 李现同款 4800万全焦段AI四摄 双光学防抖 麒麟980 全网通4G"/> </div> </li> </ul> <input type="submit" value="提交订单"/> </form> </div> </body> </html>
|
shop.css:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| ul { width: 1000px; margin: 0 auto; }
.msg { text-align: center; margin-top: 10px; font-weight: bold; font-size: larger; }
a { text-decoration: none; }
li { float: left; list-style: none; width: 250px; margin-top: 5px; height: 400px; font-size: small; }
li div { padding: 10px; }
.money { color: red; font-size: large; text-align: center; font-weight: bold; }
li:hover { box-shadow: rgba(0, 0, 0, .1) 0 0 1px 1px }
input[type=button] { border: 0; padding: 0; width: 200px; height: 30px; background: #99cc99; display: block; margin: 0 auto; }
button { margin-left: 20px; border: 0; padding: 0; width: 150px; height: 40px; background: mediumvioletred; color: white; }
input[type=button]:hover { background: #009900; }
input[type=checkbox] { border: 0; padding: 0; width: 30px; height: 25px; }
input[type=submit] { float: left; margin-left: 200px; margin-top: 150px; border: 0; padding: 0; width: 150px; height: 40px; background: limegreen; color: white; }
input[type=submit]:hover { background: green; }
|
shopCar.jsp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| <%-- Created by IntelliJ IDEA. User: 刘方涵 Date: 2019/9/24 Time: 21:55 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>购物车</title> <link rel="stylesheet" href="shopCar.css"> </head> <body> <% request.setCharacterEncoding("utf-8"); String[] phone = request.getParameterValues("choice"); if (phone == null) { %> <div class="main"> <p style="font-weight: bold">你未购买任何商品!</p> <a href="shop.jsp">前往商品页</a> </div> <% } else { double sum = 0; for (int i = 0; i < phone.length; i++) { sum = sum + Double.parseDouble(phone[i].split("¥")[0]); } %> <div class="main"> <p style="font-weight: bold">你购买的商品有:</p> <% for (int i = 0; i < phone.length; i++) { out.print(phone[i].split("¥")[1] + " 价格:" + "<span style='color: red;line-height:2em;'>" + phone[i].split("¥")[0] + "</span>元" + "<br/>"); } %> <p style="font-weight: bold">你的总花费为<span style="color: red"><%=sum%></span>元</p> <a href="shop.jsp">前往商品页</a> </div> <% } %>
</body> </html>
|
shopCar.css:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| body { background: url("../Q1/error/error.jpg"); background-size: cover; }
.main { padding: 40px; margin: 0 auto; background: hsla(0, 0%, 100%, .3); width: 700px; color: black; margin-top: 200px; }
a { float: right; text-decoration: none; color: firebrick; font-weight: bolder; }
|