主要知识点: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");
// 在这里使用jsp:forward会使得css作用不上
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;
/*margin-right: 60px;*/
}

.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;
/*display: block;*/
/*margin: 0 auto;*/
}

/*button:hover {*/
/* background: #009900;*/
/*}*/

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;
/*display: block;*/
/*margin: 0 auto;*/
}

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;
}
相关文章
评论
分享
  • JavaEE开发准备

    个人电脑硬件配置: Windows 10 64位家庭中文版 8G运行内存 Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz 1.Java JDK安装及配置(1)下载和安装首先进入oracle网站中Ja...

    JavaEE开发准备
  • JSP综合作业

    预备:数据库本次作业选择的数据库为MYSQL,采用的数据库管理工具为Navicat Premium12。MYSQL下载地址为https://dev.mysql.com/downloads/mysql/ 使用Navicat连接数据库。 ...

    JSP综合作业
  • JSP初识

    JSP(Java Server Page),由Sun公司倡导,许多公司参与,于1999年(与我年龄一样!!!)推出的一种Web服务设计标准。 注释HTML注释: 1<!--需要注释的HTML内容--> JSP注释: 1&...

    JSP初识
  • Java工具类

    API(Application Programming Interface)1.包装类Java是面向对象的语言,但其中存在基本类型,违背了面向对象的思想。 包装类是基本类型与引用类型之间交换的桥梁 类型 包装类 byte ...

    Java工具类
  • Java设计模式

    设计模式:设计模式常用的有23种。设计模式是一种设计经验的总结,为了解决某些场景下的某一类的问题,是一种通用的解决方案 创建型(5):解决对象创建的过程 结构型(7):把类或对象通过某种形式结合在一起 行为型(11):解决类或对象之间...

    Java设计模式
  • Scanner类的学习

    Scanner类导包:java.util 创建对象:Scanner input =new Scanner(System.in); 使用: int value = input.nextInt(); ​ String va...

    Scanner类的学习
  • 引用类型对象方法返回值问题

    想要通过对象方法交换两个数组中的值 目前采用了两种方法: (1)一次交换二者数组中的值 (2)交互两数组的数组名 (1) 1234567891011121314151617181920212223242526272829303132...

    引用类型对象方法返回值问题
  • Java入门到入土

    Java体系12345678910111213141516171819202122基础部分(JavaSE):1.面向对象的编程思想2.集合3.I/O流 底层MVC4.文件5.缓存6.反射、注解数据库(JDBC)+WEB(JavaEE)...

    Java入门到入土
  • Windows下neo4j的安装

    neo4j是一个高性能的NOSQL图形数据库,他将结构化数据存储在网络上而不是表中。他是一个嵌入式的、基于磁盘的、具备完全的事物特性的Java持久化引擎,neo4j也可看做是一个高性能的图引擎,该引擎具有成熟数据库的所有特性。——百度...

    Windows下neo4j的安装
  • java实现类FTP程序

    继承程序设计实验,实验说明如图所示: 集成程序设计实验 TCP实现首先说明下基于TCP实现的功能: (1)能够实现多用户的同时连接 (2)用户执行成功的命令会在其他用户终端上显式说明 (3)当前用户数以及在线情况会在服务端实时显...

    java实现类FTP程序
Please check the comment setting in config.yml of hexo-theme-Annie!