hooyantsing's Blog

第70次课程

字数统计: 14.3k阅读时长: 78 min
2019/10/25

源辰76班

第70次课程

2019.10.25

内容

JSP项目案例二[廖彦]

关系

b69dc790aaff162c4806752adacd9b22.png

分析

<公用模块>

/common

Header.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
<%@page import="java.util.*"%>
<%@page  import="com.yc.damai.util.DBHelper"%>
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<div class="container header">
    
<div class="span5">
       <div class="logo">
           <a href="index.jsp">
               <img  src="image/r___________renleipic_01/logo.png" alt="依依不舍"/>
           </a>
       </div>
    </div>
    <div class="span9">
<div class="headerAd">
    <img src="image/header.jpg" width="320"  height="50" alt="正品保障" title="正品保障"/>
</div> </div>
<div class="span10 last">
       <div class="topNav clearfix">
           <ul>
               
               
               <li id="headerLogin"  class="headerLogin" style="display:  list-item;">
                  <a href="login.jsp">登录</a>|
               </li>
               <li id="headerRegister"  class="headerRegister" style="display:  list-item;">
                  <a href="reg.jsp">注册</a>|
               </li>
               
               
               
               <li id="headerUsername"  class="headerUsername"></li>
               <li id="headerLogout"  class="headerLogout">
                  <a>[退出]</a>|
               </li>
                      <li>
                          <a>会员中心</a>
                          |
                      </li>
                      <li>
                          <a>购物指南</a>
                          |
                      </li>
                      <li>
                          <a>关于我们</a>
                          
                      </li>
           </ul>
       </div>
       <div class="cart">
           <a  href="cart.jsp">购物车</a>
       </div>
           <div class="phone">
               客服热线:
               <strong>96008/53277764</strong>
           </div>
    </div>
    
    
<div class="span24">
       <ul class="mainNav">
                  <li>
                      <a href="index.jsp">首页</a>
                      |
                  </li>
                  
                  <%
                      String cSql = "select  * from category";
                      List<Map<String,Object>> clist =  DBHelper.selectList(cSql);
                      pageContext.setAttribute("clist", clist);
                      for(Map<String,Object>  row : clist) {
                  %>
                  <li><a  href="clist.jsp?cid=<%=row.get("cid")%>"><%=row.get("cname")%></a>|</li>
                  <%}%>
                          
       </ul>
    </div>
</div>

CsList.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
<%@page import="java.util.*"%>
<%@page  import="com.yc.damai.util.DBHelper"%>
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<div class="span6">
           <div class="hotProductCategory">
               <%
                  String csSql = "select *  from categorysecond";
                  List<Map<String,Object>>  cslist = DBHelper.selectList(csSql);
                  List<Map<String,Object>>  clistCopy =  (List<Map<String,Object>>)pageContext.getAttribute("clist");
                  // clist 在上面查询过了
                  for(Map<String,Object> c  : clistCopy) {
               %>         
               <dl>
                  <dt>
                      <a  href="clist.jsp?cid=<%=c.get("cid")  %>"><%=c.get("cname") %></a>
                  </dt>
                  <%for(Map<String,Object>  cs : cslist){%>
                      <%if(cs.get("cid").equals(c.get("cid"))){%>
                      <dd>
                          <a  href="clist.jsp?csid=<%=cs.get("csid")  %>"><%=cs.get("csname") %></a>
                      </dd>
                      <%} %>
                  <%} %>
               </dl>
               <%} %>
       </div>
</div>

Footer.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
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<div class="container footer">
    <div class="span24">
       <div class="footerAd">
                  <img  src="image/footer.jpg" width="950"  height="52" alt="我们的优势" title="我们的优势"/>
</div> </div>
    <div class="span24">
       <ul class="bottomNav">
                  <li>
                      <a >关于我们</a>
                      |
                  </li>
                  <li>
                      <a>联系我们</a>
                      |
                  </li>
                  <li>
                      <a >诚聘英才</a>
                      |
                  </li>
                  <li>
                      <a >法律声明</a>
                      |
                  </li>
                  <li>
                      <a>友情链接</a>
                      |
                  </li>
                  <li>
                      <a target="_blank">支付方式</a>
                      |
                  </li>
                  <li>
                      <a  target="_blank">配送方式</a>
                      |
                  </li>
                  <li>
                      <a >SHOP++官网</a>
                      |
                  </li>
                  <li>
                      <a >SHOP++论坛</a>
                      
                  </li>
       </ul>
    </div>
    <div class="span24">
       <div class="copyright">Copyright ©  2005-2013 Mango商城 版权所有</div>
    </div>
</div>

<独立模块>

reg.jsp

注册新用户

4e730af3d91070404a824b979579878a.png

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"  content="text/html; charset=UTF-8" />
<title>大麦商城</title>
<link href="css/common.css"
    rel="stylesheet" type="text/css" />
<link href="css/register.css"
    rel="stylesheet" type="text/css" />
<script type="text/javascript"
    src="js/jquery-1.8.3.js"></script>
<script type="text/javascript">
    function checkForm(){
       // 校验用户名:
       
       // 校验密码:
       
       // 校验确认密码
       
       //校验邮箱
       return false;
    }
    
    var xmlhttp;
    // ajax 验证用户名是否存在
    try {
       xmlhttp = new  ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
       try {
           xmlhttp = new  ActiveXObject("Microsoft.XMLHTTP");
       } catch (e) {
           try {
               xmlhttp = new  XMLHttpRequest();
           } catch (e) {
           }
       }
    }
    //校验用户名是否存在
    function checkUserName(){
       
       // 获取用户填写的用户名
       var name =  document.getElementById("username").value;
       
       name = name.replace(/\s/gi,"");
       if(name == ''){
           alert("请填写用户名!");
           return;
       }
       
       if(xmlhttp!=null){
           // 定义请求地址
           var url  ="doCheckUsername.jsp?username="+name;
                  
           // 以 POST 方式 开启连接
           // POST 请求 更安全(编码)  提交的数据大小没有限制
           xmlhttp.open("POST",url,true);
           
           // 设置回调函数   // 当收到服务器的响应时,会触发该函数(回调函数)
           // 每次的状态改变都会调用该方法
           xmlhttp.onreadystatechange=function(){
               if(xmlhttp.readyState == 4 &&  xmlhttp.status == 200){
                  // 替换空格
                  var msg =  xmlhttp.responseText.replace(/\s/gi,"");
                  // 使用 span 展示错误信息,  替代 alert(msg); 提升用户体验
                  // 允许注册使用绿色字体,  否则红色字体
                  var color = msg == '该用户名可以注册!' ? 'green' : 'red';
                  // 输入框的后面一个元素是用于展示信息的 span 元素
                  $("#username").next().text(msg).css("color",  color);  
               }
           };
           // 发送请求
           xmlhttp.send(null);
       }else{
           alert("不能创建XMLHttpRequest对象实例")
       }
    }
    function changeImg(){
       // 更新验证码
    }
    
    function reg(){
       var username =  document.getElementById("username").value;
       var password =  document.getElementById("password").value;
       var repassword =  document.getElementById("repassword").value;
       var email = document.getElementById("email").value;
       var phone =  document.getElementById("phone").value;
       var name = $("#name").val();  // 使用 jquery 选择器搞定!!!
       var sex =  $("input[name='sex']:checked").val(); //  checked选择器写法记错了,已修改
       
       if(xmlhttp!=null){
           // 定义请求地址
           var url  ="doReg.jsp?username="+username
                  + "&password=" + password
                  + "&repassword=" +  repassword
                  + "&email=" + email
                  + "&phone=" + phone
                  + "&sex=" + sex;
           // 以 POST 方式 开启连接
           // POST 请求 更安全(编码)  提交的数据大小没有限制
           xmlhttp.open("POST",url,true);
           
           // 设置回调函数   // 当收到服务器的响应时,会触发该函数(回调函数)
           // 每次的状态改变都会调用该方法
           xmlhttp.onreadystatechange=function(){
               if(xmlhttp.readyState == 4 &&  xmlhttp.status == 200){
                  var json =  xmlhttp.responseText.replace(/\s/gi,"");
                  eval("var user = " +  json);
                  console.info(user);
                  alert(user.msg);  // msg  时扩展的 属性
               }
           };
           // 发送请求
           xmlhttp.send(null);
       }else{
           alert("不能创建XMLHttpRequest对象实例")
       }
       
       
    }
    </script>
</head>
<body>
    <div class="container header">
       
<div class="span5">
       <div class="logo">
           <a href="index.jsp">
               <img  src="image/r___________renleipic_01/logo.png" alt="依依不舍"/>
           </a>
       </div>
    </div>
    <div class="span9">
<div class="headerAd">
    <img src="image/header.jpg" width="320"  height="50" alt="正品保障" title="正品保障"/>
</div> </div>
<div class="span10 last">
       <div class="topNav clearfix">
           <ul>
               
               
               <li id="headerLogin"  class="headerLogin" style="display:  list-item;">
                  <a href="login.jsp">登录</a>|
               </li>
               <li id="headerRegister"  class="headerRegister" style="display:  list-item;">
                  <a href="reg.jsp">注册</a>|
               </li>
               
               
               
               <li id="headerUsername"  class="headerUsername"></li>
               <li id="headerLogout"  class="headerLogout">
                  <a>[退出]</a>|
               </li>
                      <li>
                          <a>会员中心</a>
                          |
                      </li>
                      <li>
                          <a>购物指南</a>
                          |
                      </li>
                      <li>
                          <a>关于我们</a>
                          
                      </li>
           </ul>
       </div>
       <div class="cart">
           <a  href="cart.jsp">购物车</a>
       </div>
           <div class="phone">
               客服热线:
               <strong>96008/53277764</strong>
           </div>
    </div>
       
<div class="span24">
       <ul class="mainNav">
                  <li>
                      <a href="index.jsp">首页</a>
                      |
                  </li>
                  
                  <li>
<a href="clist.jsp?1&pageIndex=1">
                  女装男装
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?2&pageIndex=1">
                  鞋靴箱包
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?3&pageIndex=1">
                  运动户外
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?4&pageIndex=1">
                  珠宝配饰
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?5&pageIndex=1">
                  手机数码
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?6&pageIndex=1">
                  家电办公
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?7&pageIndex=1">
                  护肤彩妆
</a>
                  |</li>
                          
       </ul>
    </div>
    </div>
    <div class="container register">
       <div class="span24">
           <div class="wrap">
               <div class="main clearfix">
                  <div class="title">
                      <strong>会员注册</strong>USER REGISTER
                  </div>
                  <form id="registerForm"
                      action="reg.jsp"
                      method="post"  novalidate="novalidate"
                      onsubmit="reg();  return false;">
                      <table>
                          <tbody>
                              <tr>
                                 <th><span  class="requiredField">*</span>用户名:</th>
                                 <td><input  type="text" id="username" name="username"
                                     class="text" maxlength="20"  onblur="checkUserName()" />
                                     <span  id="span1"></span>
                                 </td>
                              </tr>
                              <tr>
                                 <th><span  class="requiredField">*</span>密&nbsp;&nbsp;码:</th>
                                 <td><input  type="password" id="password"  name="password"
                                     class="text" maxlength="20"  autocomplete="off" /><span>
                                 </span></td>
                              </tr>
                              <tr>
                                 <th><span  class="requiredField">*</span>确认密码:</th>
                                 <td><input  type="password" id="repassword"
                                     name="repassword" class="text"  maxlength="20"
                                     autocomplete="off" /></td>
                              </tr>
                              <tr>
                                 <th><span  class="requiredField">*</span>E-mail:</th>
                                 <td><input  type="text" id="email" name="email"
                                     class="text" maxlength="200" /><span>
                                 </span></td>
                              </tr>
                              <tr>
                                 <th><span  class="requiredField">*</span>电话:</th>
                                 <td><input  type="text" id="phone" name="phone"
                                     class="text" maxlength="200"  onkeyup="value=value.replace(/[^\d]/g,'')"  onafterpaste="value=value.replace(/\D/g,'')">
                                 </td>
                              </tr>
                              <tr>
                                 <th>姓名:</th>
                                 <td><input  type="text" id="name" name="name"  class="text"
                                     maxlength="200">
                                 </td>
                              </tr>
                              <tr>
                                 <th>性别:</th>
                                 <td><span  class="fieldSet"> <label> <input
                                            type="radio" name="sex" value="男">男
                                     </label> <label> <input type="radio"  name="sex" value="女">女
                                         
                                     </label> </span></td>
                              </tr>
                              <!-- <tr>
                                 <th>地址:</th>
                                 <td><input  type="text" name="address" class="text"
                                     maxlength="200">
                                 </td>
                              </tr> -->
                              <tr>
                                 <th><span  class="requiredField">*</span>验证码:</th>
                                 <td><span  class="fieldSet"> <input type="text"
                                         id="captcha" name="captcha" class="text  captcha"
                                         maxlength="4" autocomplete="off"><img
                                            id="captchaImage" class="captchaImage"
                                            src="images/vcode.jpg"
                                            title="点击更换验证码" onclick="changeImg()">
                                 </span></td>
                              </tr>
                              <tr>
                                 <th>&nbsp;</th>
                                 <td><input  type="submit" class="submit" value="同意以下协议并注册">
                                 </td>
                              </tr>
                              <tr>
                                 <th>&nbsp;</th>
                                 <td>注册协议</td>
                              </tr>
                              <tr>
                                 <th>&nbsp;</th>
                                 <td>
                                     <div  id="agreement" class="agreement"  style="height: 200px;">
                                         <p>尊敬的用户欢迎您注册成为本网站会员。请用户仔细阅读以下全部内容。如用户不同意本服务条款任意内容,请不要注册或使用本网站服务。如用户通过本网站注册程序,即表示用户与本网站已达成协议,自愿接受本服务条款的所有内容。此后,用户不得以未阅读本服务条款内容作任何形式的抗辩。</p>
                                         <p>
                                            一、本站服务条款的确认和接纳
本网站涉及的各项服务的所有权和运作权归本网站所有。本网站所提供的服务必须按照其发布的服务条款和操作规则严格执行。本服务条款的效力范围及于本网站的一切产品和服务,用户在享受本网站的任何服务时,应当受本服务条款的约束。
                                         </p>
                                         <p>
                                            二、服务简介
本网站运用自己的操作系统通过国际互联网络为用户提供各项服务。用户必须: 1.
                                                提供设备,如个人电脑、手机或其他上网设备。  2. 个人上网和支付与此服务有关的费用。
                                         </p>
                                         <p>
                                            三、用户在不得在本网站上发布下列违法信息
1.  反对宪法所确定的基本原则的; 2.
                                                危害国家安全,泄露国家秘密,颠覆国家政权,破坏国家统一的; 3. 损害国家荣誉和利益的; 4.
                                                煽动民族仇恨、民族歧视,破坏民族团结的; 5.  破坏国家宗教政策,宣扬邪教和封建迷信的; 6.
                                                散布谣言,扰乱社会秩序,破坏社会稳定的; 7.  散布淫秽、色情、赌博、暴力、凶杀、恐怖或者教唆犯罪的; 8.
                                                侮辱或者诽谤他人,侵害他人合法权益的; 9.  含有法律、行政法规禁止的其他内容的。
                                         </p>
                                         <p>
                                            四、有关个人资料
用户同意: 1. 提供及时、详尽及准确的个人资料。 2. 同意接收来自本网站的信息。
                                                3. 不断更新注册资料,符合及时、详尽准确的要求。所有原始键入的资料将引用为注册资料。 4.
                                                本网站不公开用户的姓名、地址、电子邮箱和笔名。除以下情况外: a) 用户授权本站透露这些信息。  b)
                                                相应的法律及程序要求本站提供用户的个人资料。
                                         </p>
                                         <p>
                                            五、服务条款的修改
本网站有权在必要时修改服务条款,一旦条款及服务内容产生变动,本网站将会在重要页面上提示修改内容。如果不同意所改动的内容,用户可以主动取消获得的本网站信息服务。如果用户继续享用本网站信息服务,则视为接受服务条款的变动。
                                         </p>
                                         <p>
                                            六、用户隐私制度
尊重用户个人隐私是本网站的一项基本政策。所以,本网站一定不会在未经合法用户授权时公开、编辑或透露其注册资料及保存在本网站中的非公开内容,除非有法律许可要求或本网站在诚信的基础上认为透露这些信息在以下四种情况是必要的:
                                                1. 遵守有关法律规定,遵从本网站合法服务程序。 2. 保持维护本网站的商标所有权。 3.
                                                在紧急情况下竭力维护用户个人和社会大众的隐私安全。 4. 符合其他相关的要求。
                                         </p>
                                         <p>
                                            七、用户的帐号、密码和安全性
用户一旦注册成功,将获得一个密码和用户名。用户需谨慎合理的保存、使用用户名和密码。如果你不保管好自己的帐号和密码安全,将负全部责任。另外,每个用户都要对其帐户中的所有活动和事件负全责。你可随时根据指示改变你的密码。用户若发现任何非法使用用户帐号或存在安全漏洞的情况,请立即通告本网站。
                                                八、 拒绝提供担保
                                                用户明确同意信息服务的使用由用户个人承担风险。本网站不担保服务不会受中断,对服务的及时性,安全性,出错发生都不作担保,但会在能力范围内,避免出错。
                                         </p>
                                         <p>
                                            九、有限责任
如因不可抗力或其它本站无法控制的原因使本站销售系统崩溃或无法正常使用导致网上交易无法完成或丢失有关的信息、记录等本站会尽可能合理地协助处理善后事宜,并努力使客户免受经济损失,同时会尽量避免这种损害的发生。
                                         </p>
                                         <p>
                                            十、用户信息的储存和限制
本站有判定用户的行为是否符合国家法律法规规定及本站服务条款权利,如果用户违背本网站服务条款的规定,本网站有权中断对其提供服务的权利。
                                         </p>
                                         <p>
                                            十一、用户管理
用户单独承担发布内容的责任。用户对服务的使用是根据所有适用于本站的国家法律、地方法律和国际法律标准的。用户必须遵循:
                                                1. 使用网络服务不作非法用途。 2. 不干扰或混乱网络服务。 3.
                                                遵守所有使用网络服务的网络协议、规定、程序和惯例。
                                                用户须承诺不传输任何非法的、骚扰性的、中伤他人的、辱骂性的、恐性的、伤害性的、庸俗的,淫秽等信息资料。另外,用户也不能传输何教唆他人构成犯罪行为的资料;不能传输助长国内不利条件和涉及国家安全的资料;不能传输任何不符合当地法规、国家法律和国际法律的资料。未经许可而非法进入其它电脑系统是禁止的。
                                                若用户的行为不符合以上提到的服务条款,本站将作出独立判断立即取消用户服务帐号。用户需对自己在网上的行为承担法律责任。用户若在本站上散布和传播反动、色情或其它违反国家法律的信息,本站的系统记录有可能作为用户违反法律的证据。
                                         </p>
                                         <p>
                                            十二、通告
所有发给用户的通告都可通过重要页面的公告或电子邮件或常规的信件传送。服务条款的修改、服务变更、或其它重要事件的通告都会以此形式进行。
                                         </p>
                                         <p>
                                            十三、信息内容的所有权
本网站定义的信息内容包括:
                                                文字、软件、声音、相片、录象、图表;在广告中全部内容;本网站为用户提供的其它信息。所有这些内容受版权、商标、标签和其它财产所有权法律的保护。所以,用户只能在本网站和广告商授权下才能使用这些内容,而不能擅自复制、再造这些内容、或创造与内容有关的派生产品。本站所有的文章版权归原文作者和本站共同所有,任何人需要转载本站的文章,必须征得原文作者或本站授权。
                                         </p>
                                         <p>
                                            十四、法律
本协议的订立、执行和解释及争议的解决均应适用中华人民共和国的法律。用户和本网站一致同意服从本网站所在地有管辖权的法院管辖。如发生本网站服务条款与中华人民共和国法律相抵触时,则这些条款将完全按法律规定重新解释,而其它条款则依旧保持对用户的约束力。
                                         </p>
                                     </div></td>
                              </tr>
                          </tbody>
                      </table>
                      <div class="login">
                          <div class="ad">
                              <dl>
                                 <dt>注册即享受</dt>
                                 <dd>正品保障、正规发票</dd>
                                 <dd>货到付款、会员服务</dd>
                                 <dd>自由退换、售后上门</dd>
                              </dl>
                          </div>
                          <dl>
                              <dt>已经拥有账号了?</dt>
                              <dd>
                                 立即登录即可体验在线购物! <a href="login.jsp">立即登录</a>
                              </dd>
                          </dl>
                      </div>
                  </form>
               </div>
           </div>
       </div>
    </div>
    <div class="container footer">
       <div class="span24">
           <div class="footerAd">
               <img src="image/footer.jpg"
                  width="950" height="52"  alt="我们的优势" title="我们的优势">
           </div>
       </div>
       <div class="span24">
           <ul class="bottomNav">
               <li><a>关于我们</a> |</li>
               <li><a>联系我们</a> |</li>
               <li><a>招贤纳士</a> |</li>
               <li><a>法律声明</a> |</li>
               <li><a>友情链接</a> |</li>
               <li><a target="_blank">支付方式</a> |</li>
               <li><a target="_blank">配送方式</a> |</li>
               <li><a>服务声明</a> |</li>
               <li><a>广告声明</a></li>
           </ul>
       </div>
       <div class="span24">
           <div class="copyright">Copyright  © 2005-2013 Mango商城 版权所有</div>
       </div>
    </div>
    <div id="_my97DP"
       style="position: absolute; top:  -1970px; left: -1970px;">
       <iframe style="width: 190px; height:  191px;"
           src="./会员注册 - Powered By  Mango Team_files/My97DatePicker.htm"
           frameborder="0" border="0"  scrolling="no"></iframe>
    </div>
</body>
</html>

doCheckUsername.jsp

验证用户名是否可用(去重)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<%@page  import="com.yc.damai.util.DBHelper"%>
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
    String username =  request.getParameter("username");
    String sql = "select count(*) from user  where username = ?";
    Object value = DBHelper.selectValue(sql,  username);
    int count = Integer.parseInt(""+value);
    if(count>0){
       out.print("该用户已经被注册");
    }else{
       out.print("该用户可以注册");
    }
%>

doReg.jsp

新用户写入数据库的用户表(user)

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
<%@page  import="com.yc.damai.util.DBHelper"%>
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
    String username =  request.getParameter("username");
    String password =  request.getParameter("password");
    String repassword =  request.getParameter("repassword");
    String email =  request.getParameter("email");
    String phone =  request.getParameter("phone");
    String name =  request.getParameter("name");
    String sex =  request.getParameter("sex");
    String sql = "insert into user "+
       "values(null,?,?,?,?,?,?,null,null,null)";
    try{
       DBHelper.update(sql,username,password,name,email,phone,sex);
       // json 格式字符串
       
       // 定义json 返回字符串,  用于返回复杂的数据
       String json = "{name:'"+name
               +"', username:'"+username
               +"', password:'"+password
               +"', email:'"+email
               +"', phone:'"+phone
               +"', sex:'"+sex
               +"', msg:'注册成功!'}";   //  扩张一个结果描述信息
       out.print(json);
       
    } catch (Exception e){
       String json = "{msg:'注册失败!'}";    // 扩张一个结果描述信息
       out.print(json);
    }
%>

login.jsp

f7387419023f686314b2c3ded0e99965.png

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<%@ page language="java"  contentType="text/html; charset=utf-8"  pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"  content="text/html; charset=UTF-8">
<title>大麦商城</title>
<link href="css/common.css" rel="stylesheet"  type="text/css"/>
<link href="css/login.css" rel="stylesheet"  type="text/css"/>
<script type="text/javascript">
    function checkImg(){
       // 更新验证码
    }
</script>
</head>
<body>
<div class="container header">
    
<div class="span5">
       <div class="logo">
           <a href="index.jsp">
               <img  src="image/r___________renleipic_01/logo.png" alt="依依不舍"/>
           </a>
       </div>
    </div>
    <div class="span9">
<div class="headerAd">
    <img src="image/header.jpg" width="320"  height="50" alt="正品保障" title="正品保障"/>
</div> </div>
<div class="span10 last">
       <div class="topNav clearfix">
           <ul>
               
               
               <li id="headerLogin"  class="headerLogin" style="display:  list-item;">
                  <a href="login.jsp">登录</a>|
               </li>
               <li id="headerRegister"  class="headerRegister" style="display:  list-item;">
                  <a href="reg.jsp">注册</a>|
               </li>
               
               
               
               <li id="headerUsername"  class="headerUsername"></li>
               <li id="headerLogout"  class="headerLogout">
                  <a>[退出]</a>|
               </li>
                      <li>
                          <a>会员中心</a>
                          |
                      </li>
                      <li>
                          <a>购物指南</a>
                          |
                      </li>
                      <li>
                          <a>关于我们</a>
                          
                      </li>
           </ul>
       </div>
       <div class="cart">
           <a  href="cart.jsp">购物车</a>
       </div>
           <div class="phone">
               客服热线:
               <strong>96008/53277764</strong>
           </div>
    </div>
    
<div class="span24">
       <ul class="mainNav">
                  <li>
                      <a href="index.jsp">首页</a>
                      |
                  </li>
                  
                  <li>
<a href="clist.jsp?1&pageIndex=1">
                  女装男装
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?2&pageIndex=1">
                  鞋靴箱包
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?3&pageIndex=1">
                  运动户外
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?4&pageIndex=1">
                  珠宝配饰
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?5&pageIndex=1">
                  手机数码
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?6&pageIndex=1">
                  家电办公
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?7&pageIndex=1">
                  护肤彩妆
</a>
                  |</li>
                          
       </ul>
    </div>
</div>
<div class="container login">
       <div class="span12">
<div class="ad">
    <img src="image/login.jpg" width="500"  height="330" alt="会员登录" title="会员登录">
</div>     
</div>
       <div class="span12 last">
           <div class="wrap">
               <div class="main">
                  <div class="title">
                      <strong>会员登录</strong>USER LOGIN
                  </div>
                  <div class="title"  style="text-align: center;">
                      <!-- 权限控制:密码错误/请先登录 -->
                     <%if(request.getAttribute("msg")!=null){ %>
                      <font  color="red"><%=request.getAttribute("msg")%></font>
                <%}%>
                  </div>
                                        <!-- 提交表单至后台(dologin.jsp)处理数据 -->
                  <form id="loginForm"  action="dologin.jsp"  method="post"  novalidate="novalidate">
                      <table>
                          <tbody><tr>
                              <th>
                                     用户名:
                              </th>
                              <td>
                                 <input  type="text" id="username" name="username"  class="text" maxlength="20"/><span></span>
                              </td>
                          </tr>
                          <tr>
                              <th>
                                 密&nbsp;&nbsp;码:
                              </th>
                              <td>
                                 <input  type="password" id="password"  name="password" class="text" maxlength="20"  autocomplete="off"/><span></span>
                              </td>
                          </tr>
                              <tr>
                                 <th>
                                     验证码:
                                 </th>
                                 <td>
                                     <span  class="fieldSet">
                                         <input type="text" id="captcha"  name="captcha" class="text captcha"  maxlength="4" autocomplete="off"><img  id="captchaImage" class="captchaImage"  src="images/vcode.jpg" title="点击更换验证码"  onclick="checkImg()">
                                     </span>
                                 </td>
                              </tr>
                          <tr>
                              <th>&nbsp;
                                 
                              </th>
                              <td>
                                 <label>
                                     <input  type="checkbox" id="isRememberUsername"  name="isRememberUsername" value="true">记住用户名
                                 </label>
                                 <label>
                                     &nbsp;&nbsp;<a >找回密码</a>
                                 </label>
                              </td>
                          </tr>
                          <tr>
                              <th>&nbsp;
                                 
                              </th>
                              <td>
                                 <input  type="submit" class="submit" value="登 录">
                              </td>
                          </tr>
                          <tr  class="register">
                              <th>&nbsp;
                                 
                              </th>
                              <td>
                                 <dl>
                                     <dt>还没有注册账号?</dt>
                                     <dd>
                                         立即注册即可体验在线购物!
                                         <a  href="reg.jsp">立即注册</a>
                                     </dd>
                                 </dl>
                              </td>
                          </tr>
                      </tbody></table>
                  </form>
               </div>
           </div>
       </div>
    </div>
<div class="container footer">
    <div class="span24">
      <div class="footerAd"><img  src="image/footer.jpg" width="950"  height="52" alt="我们的优势" title="我们的优势" /></div>   
    </div>
    <div class="span24">
       <ul class="bottomNav">
                  <li>
                      <a >关于我们</a>
                      |
                  </li>
                  <li>
                      <a>联系我们</a>
                      |
                  </li>
                  <li>
                      <a>招贤纳士</a>
                      |
                  </li>
                  <li>
                      <a>法律声明</a>
                      |
                  </li>
                  <li>
                      <a>友情链接</a>
                      |
                  </li>
                  <li>
                      <a target="_blank">支付方式</a>
                      |
                  </li>
                  <li>
                      <a  target="_blank">配送方式</a>
                      |
                  </li>
                  <li>
                      <a>服务声明</a>
                      |
                  </li>
                  <li>
                      <a>广告声明</a>
                      
                  </li>
       </ul>
    </div>
    <div class="span24">
       <div class="copyright">Copyright ©  2005-2013 Mango商城 版权所有</div>
    </div>
</div>
</body></html>

dologin.jsp

前端传送过来的表单,与数据库的数据匹配

要点:

1.跳转页面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<%@ page import="java.util.*"%>
<%@ page  import="com.yc.damai.util.DBHelper"%>
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
    // 设置请求对象的字符集编码,可以兼容中文参数,避免乱码问题
    request.setCharacterEncoding("utf-8");
    // 接收 用户名 和 密码
    String username =  request.getParameter("username");
    String password =  request.getParameter("password");
    String sql = "select * from user where  username=? and password=?";
    Map<String, Object> user =  DBHelper.selectOne(sql, username, password);
    if (user != null) {
       session.setAttribute("loginedUser",  user);
        //匹配成功,跳转至主页(index.jsp)
       response.sendRedirect("index.jsp");
    } else {
       request.setAttribute("msg", "用户名或密码错误!");
        //匹配失败,跳转至登录页(login.jsp)重新登陆
       request.getRequestDispatcher("login.jsp").forward(request, response);
    }
%>

index.jsp

要点:

1.MySQL数据库分页

2.动态生成页面元素

5bc5690ac1dc62e6b7b5bcad9a0bd599.png

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<%@page import="java.util.*"%>
<%@page  import="com.yc.damai.util.DBHelper"%>
<%@page  import="com.sun.corba.se.spi.ior.iiop.RequestPartitioningComponent"%>
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"  content="text/html; charset=UTF-8"/>
<title>大麦商城</title>
<link href="css/slider.css" rel="stylesheet"  type="text/css"/>
<link href="css/common.css" rel="stylesheet"  type="text/css"/>
<link href="css/index.css" rel="stylesheet"  type="text/css"/>
</head>
<body>
<div class="container header">
    
    
<div class="span5">
       <div class="logo">
           <a href="index.jsp">
               <img  src="image/r___________renleipic_01/logo.png" alt="依依不舍"/>
           </a>
       </div>
    </div>
    <div class="span9">
<div class="headerAd">
    <img src="image/header.jpg" width="320"  height="50" alt="正品保障" title="正品保障"/>
</div> </div>
<div class="span10 last">
       <div class="topNav clearfix">
           <ul>
               
                  <li id="headerLogin"  class="headerLogin" style="display:  list-item;">
                      Song|
                  </li>
                  <li id="headerLogin"  class="headerLogin" style="display:  list-item;">
                      <a href="olist.jsp">我的订单</a>|
                  </li>
                  <li id="headerRegister"  class="headerRegister" style="display:  list-item;">
                  <a href="index.jsp">退出</a>|
               </li>
               
               
               
               
               <li id="headerUsername"  class="headerUsername"></li>
               <li id="headerLogout"  class="headerLogout">
                  <a>[退出]</a>|
               </li>
                      <li>
                          <a>会员中心</a>
                          |
                      </li>
                      <li>
                          <a>购物指南</a>
                          |
                      </li>
                      <li>
                          <a>关于我们</a>
                          
                      </li>
           </ul>
       </div>
       <div class="cart">
           <a  href="cart.jsp">购物车</a>
       </div>
           <div class="phone">
               客服热线:
               <strong>96008/53277764</strong>
           </div>
    </div>
    
<div class="span24">
       <ul class="mainNav">
                  <li>
                      <a href="index.jsp">首页</a>
                      |
                  </li>
                  
                  <li>
<a href="clist.jsp?1&pageIndex=1">
                  女装男装
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?2&pageIndex=1">
                  鞋靴箱包
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?3&pageIndex=1">
                  运动户外
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?4&pageIndex=1">
                  珠宝配饰
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?5&pageIndex=1">
                  手机数码
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?6&pageIndex=1">
                  家电办公
</a>
                  |</li>
                  
                  <li>
<a href="clist.jsp?7&pageIndex=1">
                  护肤彩妆
</a>
                  |</li>
                          
       </ul>
    </div>
</div>
<div class="container index">
       
       <div class="span24">
           <div id="hotProduct"  class="hotProduct clearfix">
                  <div class="title">
                      <strong>热门商品</strong>
                      <!-- <a   target="_blank"></a> -->
                  </div>
                  <ul class="tab">
                          <li  class="current">
                              <a href="./蔬菜分类.htm?tagIds=1" target="_blank"></a>
                          </li>
                          <li>
                              <a   target="_blank"></a>
                          </li>
                          <li>
                              <a  target="_blank"></a>
                          </li>
                  </ul>
                      <ul class="tabContent"  style="display: block;">
                          <%
                              String  paramNumber =  request.getParameter("pageNumber");
                              String  paramRows =  request.getParameter("pageRows");
                              //第几页
                              int pageNumber  = paramNumber == null ? 1 :  Integer.parseInt(paramNumber);
                              //每页行数
                              int pageRows =  paramRows == null ? 10 :  Integer.parseInt(paramRows);
                              //第几页开始查询
                              int beginRow =  (pageNumber - 1) * 10;
                              
                              String sql =  "select count(*) from product where is_hot =  1";
                              //
                              Object value =  DBHelper.selectValue(sql);
                              int totalRows  = Integer.parseInt(""+value);
                              int totalPage  = totalRows / pageRows;
                              totalPage +=  totalRows % pageRows == 0 ? 0 : 1;
                              
                              
                              sql = "select  * from product where is_hot=1 limit ?,?";
                              List<Map<String,Object>> list =
                                     DBHelper.selectList(sql, beginRow,pageRows);
                              for(Map<String,Object> m : list){
                          %>
                              <li>
                                     <a  target="_blank" href="detail.jsp?1"><img  src="<%=m.get("image") %>" style="display:  block;"></a>
                              </li>
                          <%} %>
                          
                      </ul>
                      <a  href="index.jsp?pageNumber=1">首页</a>
                      <a  href="index.jsp?pageNumber=<%=pageNumber<=1  ? 1 : pageNumber-1 %>">上一页</a>
                      <a  href="index.jsp?pageNumber=<%=pageNumber>=totalPage ? totalPage : pageNumber+1 %>">下一页</a>
                      <a  href="index.jsp?pageNumber=<%=totalPage%>">尾页</a>
           </div>
       </div>
       <div class="span24">
           <div id="newProduct"  class="newProduct clearfix">
                  <div class="title">
                      <strong>最新商品</strong>
                      <a   target="_blank"></a>
                  </div>
                  <ul class="tab">
                          <li  class="current">
                              <a href="./蔬菜分类.htm?tagIds=2" target="_blank"></a>
                          </li>
                          <li>
                              <a   target="_blank"></a>
                          </li>
                          <li>
                              <a  target="_blank"></a>
                          </li>
                  </ul>             
                       <ul  class="tabContent" style="display: block;">
                       
                                 <li>
                                     <a  href="detail.jsp?72" target="_blank"><img  src="products/1/cs10011.jpg" style="display:  block;"></a>
                                 </li>
                      
                                 <li>
                                     <a  href="detail.jsp?57" target="_blank"><img  src="products/1/cs60006.png" style="display:  block;"></a>
                                 </li>
                      
                                 <li>
                                     <a  href="detail.jsp?4" target="_blank"><img  src="products/1/cs10004.jpg" style="display:  block;"></a>
                                 </li>
                      
                                 <li>
                                     <a  href="detail.jsp?45" target="_blank"><img  src="products/1/cs50004.png" style="display:  block;"></a>
                                 </li>
                      
                                 <li>
                                     <a  href="detail.jsp?51" target="_blank"><img  src="products/1/cs50010.png" style="display:  block;"></a>
                                 </li>
                      
                                 <li>
                                     <a  href="detail.jsp?68" target="_blank"><img  src="products/1/cs70007.png" style="display:  block;"></a>
                                 </li>
                      
                                 <li>
                                     <a  href="detail.jsp?60" target="_blank"><img  src="products/1/cs60009.png" style="display:  block;"></a>
                                 </li>
                      
                                 <li>
                                     <a  href="detail.jsp?30" target="_blank"><img  src="products/1/cs30010.png" style="display:  block;"></a>
                                 </li>
                      
                                 <li>
                                     <a  href="detail.jsp?6" target="_blank"><img  src="products/1/cs10006.jpg" style="display:  block;"></a>
                                 </li>
                      
                                 <li>
                                     <a  href="detail.jsp?2" target="_blank"><img  src="products/1/cs10002.jpg" style="display:  block;"></a>
                                 </li>
                      
                      </ul>
           </div>
       </div>
       <div class="span24">
           <div class="friendLink">
               <dl>
                  <dd>新手指南</dd>
                          <dd>
                              <a   target="_blank">支付方式</a>
                              |
                          </dd>
                          <dd>
                              <a   target="_blank">配送方式</a>
                              |
                          </dd>
                          <dd>
                              <a   target="_blank">售后服务</a>
                              |
                          </dd>
                          <dd>
                              <a   target="_blank">购物帮助</a>
                              |
                          </dd>
                          <dd>
                              <a   target="_blank">蔬菜卡</a>
                              |
                          </dd>
                          <dd>
                              <a   target="_blank">礼品卡</a>
                              |
                          </dd>
                          <dd>
                              <a  target="_blank">银联卡</a>
                              |
                          </dd>
                          <dd>
                              <a   target="_blank">亿家卡</a>
                              |
                          </dd>
                          
                  <dd class="more">
                      <a >更多</a>
                  </dd>
               </dl>
           </div>
       </div>
    </div>
<div class="container footer">
    <div class="span24">
       <div class="footerAd">
                  <img  src="image/footer.jpg" width="950"  height="52" alt="我们的优势" title="我们的优势">
</div> </div>
    <div class="span24">
       <ul class="bottomNav">
                  <li>
                      <a>关于我们</a>
                      |
                  </li>
                  <li>
                      <a>联系我们</a>
                      |
                  </li>
                  <li>
                      <a>招贤纳士</a>
                      |
                  </li>
                  <li>
                      <a>法律声明</a>
                      |
                  </li>
                  <li>
                      <a>友情链接</a>
                      |
                  </li>
                  <li>
                      <a target="_blank">支付方式</a>
                      |
                  </li>
                  <li>
                      <a target="_blank">配送方式</a>
                      |
                  </li>
                  <li>
                      <a>服务声明</a>
                      |
                  </li>
                  <li>
                      <a>广告声明</a>
                      
                  </li>
       </ul>
    </div>
    <div class="span24">
       <div class="copyright">Copyright ©  2005-2013 大麦商城 版权所有</div>
    </div>
</div>
</body></html>

clist.jsp

多参数选择页面(cid,csid,page)

要点:

1.多参数选择,若两参数选择其一(cid/csid),可用三元表达式。

2.使用DBHelper工具类调用MySQL分页方法

05a9334cd4a052e0660390cd3572ae65.png

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<%@page import="java.util.*"%>
<%@page  import="com.yc.damai.util.DBHelper"%>
<%@ page language="java"  contentType="text/html; charset=utf-8"  pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"  content="text/html; charset=UTF-8"/>
<title>大麦商城</title>
<link href="css/common.css" rel="stylesheet"  type="text/css"/>
<link href="css/product.css"  rel="stylesheet" type="text/css"/>
</head>
<body>
<%@ include file="/common/Header.jsp" %>
<div class="container productList">
    
       <%-- 左边的子类 --%>
       <%@ include  file="/common/CsList.jsp" %>
       
       <div class="span18 last">
           
           <form id="productForm"  action="image/蔬菜 - Powered By Mango  Team.htm" method="get">
               <input type="hidden"  id="brandId" name="brandId" value=""/>
               <input type="hidden"  id="promotionId" name="promotionId"  value=""/>
               <input type="hidden"  id="orderType" name="orderType" value=""/>
               <input type="hidden"  id="pageNumber" name="pageNumber"  value="1"/>
               <input type="hidden"  id="pageSize" name="pageSize" value="20"/>
                  
               <div id="result"  class="result table clearfix">
                      <ul>
                      <%
                          String sql =  "select a.* from product a join  categorysecond b "
                              + " on a.csid  = b.csid"
                              + " where  1=1";
                          String cid =  request.getParameter("cid");
                          String csid =  request.getParameter("csid");
                          // 第几页
                          String pageParam =  request.getParameter("page");

                          int iPage =  pageParam == null ? 1 :  Integer.parseInt(pageParam);

                          // 每页行数
                          int rows = 12;
                          
                          String queryId;
                          if(csid!=null){
                              sql += " and  b.csid=?";
                              queryId =  csid;
                          } else {
                              sql += " and  b.cid=?";
                              queryId = cid;
                          }

                          //使用DBHelper工具类中的MySQL分页查询方法
                          DBHelper.Page  pPage =  DBHelper.selectPageForMysql(sql,iPage,rows,  queryId);
 
                          //生成右侧商品目录
                          for(Map<String,Object> p : pPage.getData()){
                      %>
                      
                          <li>
                                    <!-- 点击右侧商品进入详情页面(detail.jsp) -->
                              <a  href="detail.jsp?pid=<%=p.get("pid")%>">
                                 <img  src="<%=p.get("image") %>" width="170"  height="170"  style="display:  inline-block;"/>
                                    
                                 <span  style='color:green'>
                                   <%=p.get("pname") %>
                                 </span>
                                  
                                 <span  class="price">
                                     商城价:  ¥<%=p.get("shop_price") %>/份
                                 </span>
                                  
                              </a>
                          </li>

                      <%}%>
                      
                      </ul>
               </div>
    
    <!-- 分页 -->
    <div class="pagination">
       第<%=pPage.getPage()  %>/<%=pPage.getLastPage()%>
       
               <% String condition = csid !=  null ? "csid=" + csid : ("cid=" + cid);%>
    
               <a class="firstPage"  href="clist.jsp?<%=condition  %>&page=1">&nbsp;</a>
               <a class="previousPage"  href="clist.jsp?<%=condition  %>&page=<%=pPage.getPreviousPage()%>">&nbsp;</a>
           
                  <%for(int i=1;  i<=pPage.getLastPage() ; i++){ %>
                  
                      <%if(pPage.getPage()==i){ %>
                            <!-- 当前页特殊的样式 -->
                          <span  class="currentPage"><%=i%></span>
                      <%} else { %>
                          <a  href="clist.jsp?<%=condition  %>&page=<%=i%>"><%=i%></a>
                      <%} %>
               
                  <%} %>
           
               <a class="nextPage"  href="clist.jsp?<%=condition  %>&page=<%=pPage.getNextPage()%>">&nbsp;</a>
               <a class="lastPage"  href="clist.jsp?<%=condition  %>&page=<%=pPage.getLastPage()%>">&nbsp;</a>
               
    </div>
           </form>
       </div>
    </div>
    
<jsp:include  page="/common/Footer.jsp"></jsp:include>
</body></html>

detail.jsp

单商品详情页面

4972032ef51f507ffb0c5532ac57b9be.png

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<%@page import="java.util.*"%>
<%@page  import="com.yc.damai.util.DBHelper"%>
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"  content="text/html; charset=UTF-8"/>
<link href="css/common.css" rel="stylesheet"  type="text/css"/>
<link href="css/product.css"  rel="stylesheet" type="text/css"/>
<script type="text/javascript"  src="js/jquery.js"></script>
<script type="text/javascript"  src="js/common.js"></script>
<title>大麦商城</title>
</head>
<body>
<%@ include file="/common/Header.jsp" %>
<%
String pid = request.getParameter("pid");
String sql = "select * from product where  pid=?";
Map<String,Object> product =  DBHelper.selectOne(sql, pid);
//将 商品 map 添加到页面上下文中, 就是用 EL  表达式输出值
pageContext.setAttribute("p", product);
%>
<div class="container productContent">
       <%-- 左边的子类 --%>
       <%@ include  file="/common/CsList.jsp" %>
    
    
       <div class="span18 last">
           
           <div class="productImage">
                  <a title=""  style="outline-style: none; text-decoration:  none;" id="zoom"  href="http://image/r___________renleipic_01/bigPic1ea8f1c9-8b8e-4262-8ca9-690912434692.jpg" rel="gallery">
                      <div  class="zoomPad"><img style="opacity: 1;"  title="" class="medium"  src="${p.image}"><div style="display: block;  top: 0px; left: 162px; width: 0px; height:  0px; position: absolute; border-width: 1px;"  class="zoomPup"></div><div style="position:  absolute; z-index: 5001; left: 312px; top:  0px; display: block;"  class="zoomWindow"><div style="width:  368px;" class="zoomWrapper"><div  style="width: 100%; position: absolute;  display: none;"  class="zoomWrapperTitle"></div><div  style="width: 0%; height: 0px;"  class="zoomWrapperImage"><img  src="%E5%B0%9A%E9%83%BD%E6%AF%94%E6%8B%89%E5%A5%B3%E8%A3%852013%E5%A4%8F%E8%A3%85%E6%96%B0%E6%AC%BE%E8%95%BE%E4%B8%9D%E8%BF%9E%E8%A1%A3%E8%A3%99%20%E9%9F%A9%E7%89%88%E4%BF%AE%E8%BA%AB%E9%9B%AA%E7%BA%BA%E6%89%93%E5%BA%95%E8%A3%99%E5%AD%90%20%E6%98%A5%E6%AC%BE%20-%20Powered%20By%20Mango%20Team_files/6d53c211-2325-41ed-8696-d8fbceb1c199-large.jpg"  style="position: absolute; border: 0px none;  display: block; left: -432px; top:  0px;"></div></div></div><div  style="visibility: hidden; top: 129.5px;  left: 106px; position: absolute;"  class="zoomPreload">Loading zoom</div></div>
                  </a>
               
           </div>
           <div  class="name">${p.pname}</div>
           <div class="sn">
               <div>编号:${p.pid}</div>
           </div>
           <div class="info">
               <dl>
                  <dt>商城价:</dt>
                  <dd>
                      <strong>¥:${p.shop_price}元/份</strong>
                          参 考 价:
                          <del>¥${p.market_price}元/份</del>
                  </dd>
               </dl>
                  <dl>
                      <dt>促销:</dt>
                      <dd>
                              <a  target="_blank" title="限时抢购 (2014-07-30  ~ 2015-01-01)">限时抢购</a>
                      </dd>
                  </dl>
                  <dl>
                      <dt>    </dt>
                      <dd>
                          <span>    </span>
                      </dd>
                  </dl>
           </div>
               <div class="action">
                  <form  action="doAddCart.jsp" method="post">
                      <input type="hidden"  name="pid" value="${p.pid }"/>
                      <dl class="quantity">
                          <dt>购买数量:</dt>
                          <dd>
                              <input  id="quantity" name="count" value="1"  maxlength="4" onpaste="return false;"  type="text">
                              <div>
                                 <span  id="increase" class="increase">&nbsp;</span>
                                 <span  id="decrease" class="decrease">&nbsp;</span>
                              </div>
                          </dd>
                          <dd>
                              件
                          </dd>
                      </dl>
                  <div class="buy">
                          <input  id="addCart" class="addCart" value="加入购物车" type="submit">
                  </div>
               </form>
               </div>
           <div id="bar" class="bar">
               <ul>
                      <li  id="introductionTab">
                          <a  href="#introduction">商品介绍</a>
                      </li>
                      
               </ul>
           </div>
               
               <div id="introduction"  name="introduction" class="introduction">
                  <div class="title">
                      <strong>商品介绍</strong>
                  </div>
                  <div>
                      ${p.pdesc}
                      <br /><br />
                      <img src="${p.image}"  align="middle"/>
                  </div>
               </div>
               
               
               
       </div>
    </div>
    
<jsp:include  page="/common/Footer.jsp"></jsp:include>
</body>
</html>

doAddCart.jsp

商品添加到购物车

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<%@page import="java.util.Map"%>
<%@page  import="com.yc.damai.util.DBHelper"%>
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
    Map<String,Object> user =  (Map<String,Object>)session.getAttribute("loginedUser");
    String pid =  request.getParameter("pid");
    String count =  request.getParameter("count");
    String sql = "update cartitem set  count=count+? where uid=? and pid=?";
    // 判断是否更新到 指定用的商品
    int num = DBHelper.update(sql,count,   user.get("uid"), pid);
    
    if(num == 0 ){
       sql = "insert into cartitem  values(null,?,?,?)";
       DBHelper.update(sql,  user.get("uid"), pid, count);
    }
    
    response.sendRedirect("cart.jsp");
%>

cart.jsp

购物车

3c87ae79439b8648bfc5b95a882af9b1.png

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
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"  content="text/html; charset=UTF-8"/>
<title>大麦商城</title>
<link href="css/common.css" rel="stylesheet"  type="text/css">
<link href="css/cart.css" rel="stylesheet"  type="text/css">
<script type="text/javascript"  src="js/jquery.js"></script>
<script type="text/javascript"  src="js/common.js"></script>
</head>
<%
    if(session.getAttribute("loginedUser")  == null){
       request.setAttribute("msg", "请先登录系统!");
       request.getRequestDispatcher("login.jsp").forward(request, response);
       return;
    }
%>
<body>
<%@ include file="/common/Header.jsp" %>
    <div class="container cart">
       <div class="span24">
       
       
       <div class="step step1">
               购物车列表
           </div>
               <table>
                  <tbody><tr>
                      <th>图片</th>
                      <th>商品</th>
                      <th>价格</th>
                      <th>数量</th>
                      <th>小计</th>
                      <th>操作</th>
                  </tr>
                  <%
                      String sql = "select  b.*,a.ciid,a.count from cartitem a"
                                 + " join  product b on a.pid=b.pid where uid = ?";
                      Map<String,Object>  user =  (Map<String,Object>)session.getAttribute("loginedUser");
                      List<Map<String,Object>> list =  DBHelper.selectList(sql,user.get("uid"));
                      for(Map<String,Object>  cartitem : list){
                          pageContext.setAttribute("c", cartitem);
                  %>
                      <tr>
                          <td width="60">
                              <img  src="${c.image }">
                          </td>
                          <td>
                              <a  target="_blank">${c.pname }</a>
                          </td>
                          <td>
                              ¥${c.shop_price }
                          </td>
                          <td  class="quantity" width="60">
                              ${c.count }
                          </td>
                          <td width="140">
                              <span  class="subtotal">¥${c.shop_price * c.count  }</span>
                          </td>
                          <td>
                              <a  href="cart.jsp?pid=1" class="delete">删除</a>
                          </td>
                      </tr>
               <%} %>
               </tbody></table>
               
               <dl id="giftItems"  class="hidden" style="display: none;">
               </dl>
               <div class="total">
                  <em id="promotion"></em>
                          <em>
                              登录后确认是否享有优惠
                          </em>
                  赠送积分: <em  id="effectivePoint">11017.0</em>
                  商品金额: <strong  id="effectivePrice">11017.0</strong>
               </div>
               <div class="bottom">
                  <a href="cart.jsp"  id="clear" class="clear">清空购物车</a>
                  <a href="pay.jsp"  id="submit" class="submit">提交订单</a>
               </div>
           
       </div>
    </div>
<jsp:include  page="/common/Footer.jsp"></jsp:include>
</body></html>

pay.jsp

订单支付页面

be9de17babacb004299accf344d9dd38.png

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"  content="text/html; charset=UTF-8"/>
<title>大麦商城</title>
<link href="css/common.css" rel="stylesheet"  type="text/css"/>
<link href="css/cart.css" rel="stylesheet"  type="text/css"/>
</head>
<body>
<%@ include file="/common/Header.jsp" %>
<div class="container cart">
       <div class="span24">
       
           <div class="step step1">
               <ul>
                  
                  <li   class="current"></li>
                  <li  >生成订单成功</li>
                  <li  >订单号:73</li>
               </ul>
           </div>
       
               <table>
                  <tbody>
                  <tr>
                      <th>图片</th>
                      <th>商品</th>
                      <th>价格</th>
                      <th>数量</th>
                      <th>小计</th>
                  </tr>
                  
                  
                  <%
                      String sql = "select  b.*,a.ciid,a.count from cartitem a "
                              + " join  product b on a.pid=b.pid where uid=?";
                      Map<String,Object>  user =  (Map<String,Object>)session.getAttribute("loginedUser");
                      List<Map<String,Object>> list =  DBHelper.selectList(sql, user.get("uid"));
                      for(Map<String,Object>  cartitem : list){
                          pageContext.setAttribute("c", cartitem);
                  %>
               
                  
                  
                      <tr>
                          <td width="60">
                              <img  src="${c.image}"/>
                          </td>
                          <td>
                              <a  target="_blank">${c.pname }</a>
                          </td>
                          <td>
                              ${c.shop_price  }
                          </td>
                          <td  class="quantity" width="60">
                                 ${c.count }                          
                          </td>
                          <td width="140">
                              <span  class="subtotal">¥${c.shop_price *  c.count}</span>
                          </td>
                      </tr>
                  
                      <%} %>
                      
                  
               </tbody>
           </table>
               <dl id="giftItems"  class="hidden" style="display: none;">
               </dl>
               <div class="total">
                  <em id="promotion"></em>
                  商品金额: <strong  id="effectivePrice">¥????????????元</strong>
               </div>
           <form id="orderForm"  action="doAddOrder.jsp" method="post">
               <input type="hidden"  name="order.oid" value="73"/>
               <div class="span24">
                  <p>
                          收货地址:<input  name="order.addr" type="text" value=""  style="width:350px" />
                              <br />
                          收货人&nbsp;&nbsp;&nbsp;:<input name="order.name" type="text"  value="" style="width:150px" />
                              <br />
                          联系方式:<input  name="order.phone" type="text" value=""  style="width:150px" />
                      </p>
                      <hr />
                      <p>
                          选择银行:<br/>
                          <input  type="radio" name="pd_FrpId"  value="ICBC-NET-B2C" checked="checked"/>工商银行
                          <img  src="bank_img/icbc.bmp"  align="middle"/>&nbsp;&nbsp;&nbsp;&nbsp;
                          <input  type="radio" name="pd_FrpId"  value="BOC-NET-B2C"/>中国银行
                          <img  src="bank_img/bc.bmp"  align="middle"/>&nbsp;&nbsp;&nbsp;&nbsp;
                          <input  type="radio" name="pd_FrpId"  value="ABC-NET-B2C"/>农业银行
                          <img  src="bank_img/abc.bmp" align="middle"/>
                          <br/>
                          <input  type="radio" name="pd_FrpId"  value="BOCO-NET-B2C"/>交通银行
                          <img  src="bank_img/bcc.bmp"  align="middle"/>&nbsp;&nbsp;&nbsp;&nbsp;
                          <input  type="radio" name="pd_FrpId"  value="PINGANBANK-NET"/>平安银行
                          <img  src="bank_img/pingan.bmp"  align="middle"/>&nbsp;&nbsp;&nbsp;&nbsp;
                          <input  type="radio" name="pd_FrpId"  value="CCB-NET-B2C"/>建设银行
                          <img  src="bank_img/ccb.bmp" align="middle"/>
                          <br/>
                          <input  type="radio" name="pd_FrpId"  value="CEB-NET-B2C"/>光大银行
                          <img  src="bank_img/guangda.bmp"  align="middle"/>&nbsp;&nbsp;&nbsp;&nbsp;
                          <input  type="radio" name="pd_FrpId"  value="CMBCHINA-NET-B2C"/>招商银行
                          <img  src="bank_img/cmb.bmp" align="middle"/>
                      </p>
                      <hr />
                      <p  style="text-align:right">
                            //通过a标签激发js语句
                          <a  href="javascript:document.getElementById('orderForm').submit();">
                              <img  src="images/finalbutton.gif" width="204"  height="51" border="0" />
                          </a>
                      </p>
               </div>
           </form>
       </div>
       
    </div>
<jsp:include  page="/common/Footer.jsp"></jsp:include>
</body>
</html>

doAddOrder.jsp

提交订单,将购物车数据写入数据库的订单表(orders)

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
<%@page import="java.util.List"%>
<%@page  import="com.yc.damai.util.DBHelper"%>
<%@page import="java.util.Map"%>
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
    Map<String,Object> user =  (Map<String,Object>)session.getAttribute("loginedUser");
    Integer uid = (Integer)user.get("uid");
    String addr =  request.getParameter("order.addr");
    String phone =  request.getParameter("order.phone");
    String name =  request.getParameter("order.name");
    
    // total 字段 暂时设置为 null
    String sql = "insert into orders  values(null, null, now(), 1, ?, ?, ? , ?)";
    DBHelper.update(sql, addr, phone, uid,  name);
    
    // 获取刚才添加的订单编号
    String oid = "" +  DBHelper.selectValue("select max(oid) from  orders");
    
    sql = "select a.*,b.shop_price from  cartitem a join product b on a.pid=b.pid  where uid=?";
    
    List<Map<String,Object>> list =  DBHelper.selectList(sql, uid);
    
    // 写入订单明细
    for(Map<String,Object> cartitem : list){
       sql = "insert into orderitem values  (null, ?, ? * ?, ?, ?)";
       DBHelper.update(sql,  cartitem.get("count"),
               cartitem.get("count"),
               cartitem.get("shop_price"),
               cartitem.get("pid"),
               oid);
    }
    
    // 清空购物车!!!!
    request.getRequestDispatcher("msg.jsp").forward(request, response);
%>

msg.jps

网购结束

6952cac85f8b8d71112afc39351483ec.png

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
<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
  <head>
    <title>大麦商城</title>
    
    <meta http-equiv="pragma"  content="no-cache">
    <meta http-equiv="cache-control"  content="no-cache">
    <meta http-equiv="expires" content="0">    
    <link href="css/style.css"  rel="stylesheet" type="text/css"/>
  </head>
  
  <body>
<div id="divcontent">
<table width="850px" border="0"  cellspacing="0">
  <tr>
    <td style="padding:30px;  text-align:center"><table width="60%"  border="0" cellspacing="0"  style="margin-top:70px">
      <tr>
        <td style="width:98"><img  src="images/IconTexto_WebDev_009.jpg"  width="128" height="128" /></td>
        <td style="padding-top:30px"><font  style="font-weight:bold; color:#FF0000"> <ul  class="actionMessage">
                <li><span>信息提示页面,请在此处展示信息给用户查看</span></li>
    </ul>
</font><br />
            <br />
          <a href="index.jsp">首页</a>
          <a href="reg.jsp">注册</a>
          <a href="login.jsp">登录</a>
         </td>
      </tr>
    </table>
    <h1>&nbsp;</h1></td>
    </tr>
</table>
</div>
</body>
</html>
CATALOG