Beifengdo commited on
Commit
2f1e861
·
verified ·
1 Parent(s): 0b3174f

Upload original JavaEE(考查答辩 I 主线任务 配置换环境) course files (part 2)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. JavaEEweb程序设计实验2026-王非老师-范纯毓/workspace/study5/ssh-student/WebContent/WEB-INF/views/edit.jsp +110 -0
  2. JavaEEweb程序设计实验2026-王非老师-范纯毓/workspace/study5/ssh-student/WebContent/WEB-INF/views/list.jsp +126 -0
  3. JavaEEweb程序设计实验2026-王非老师-范纯毓/workspace/study5/ssh-student/WebContent/WEB-INF/web.xml +55 -0
  4. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/README.md +60 -0
  5. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/jsp-login/WebContent/login.jsp +91 -0
  6. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/jsp-login/WebContent/success.jsp +83 -0
  7. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/servlet-login/WebContent/WEB-INF/web.xml +30 -0
  8. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/servlet-login/WebContent/login.html +84 -0
  9. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/servlet-login/WebContent/success.jsp +74 -0
  10. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/servlet-login/src/com/example/LoginServlet.java +49 -0
  11. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/struts2-login/WebContent/WEB-INF/web.xml +25 -0
  12. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/struts2-login/WebContent/login.jsp +95 -0
  13. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/struts2-login/WebContent/success.jsp +74 -0
  14. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/struts2-login/src/com/example/LoginAction.java +50 -0
  15. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/struts2-login/src/struts.xml +15 -0
  16. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/README.md +40 -0
  17. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/WebContent/WEB-INF/web.xml +14 -0
  18. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/WebContent/index.jsp +169 -0
  19. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/WebContent/login.jsp +142 -0
  20. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/WebContent/logout.jsp +47 -0
  21. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/WebContent/register.jsp +150 -0
  22. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/src/com/netshop/Product.java +76 -0
  23. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/src/com/netshop/User.java +57 -0
  24. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/README.md +27 -0
  25. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/WebContent/WEB-INF/web.xml +10 -0
  26. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/WebContent/input.jsp +48 -0
  27. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/WebContent/login.jsp +40 -0
  28. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/WebContent/success.jsp +29 -0
  29. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/src/com/example/LoginAction.java +26 -0
  30. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/src/com/example/StudentAction.java +35 -0
  31. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/src/struts.xml +20 -0
  32. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study4/README.md +31 -0
  33. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study4/WebContent/WEB-INF/web.xml +10 -0
  34. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study4/WebContent/register.jsp +75 -0
  35. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study4/WebContent/success.jsp +28 -0
  36. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study4/src/com/example/RegisterAction.java +108 -0
  37. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study4/src/struts.xml +10 -0
  38. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study5/README.md +24 -0
  39. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study5/WebContent/WEB-INF/web.xml +10 -0
  40. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study5/WebContent/display.jsp +46 -0
  41. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study5/WebContent/search.jsp +33 -0
  42. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study5/src/com/example/SearchAction.java +58 -0
  43. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study5/src/struts.xml +10 -0
  44. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/README.md +40 -0
  45. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/WebContent/WEB-INF/web.xml +5 -0
  46. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/WebContent/add.jsp +14 -0
  47. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/WebContent/delete.jsp +8 -0
  48. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/WebContent/edit.jsp +60 -0
  49. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/WebContent/index.jsp +75 -0
  50. JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/WebContent/newgoods.jsp +53 -0
JavaEEweb程序设计实验2026-王非老师-范纯毓/workspace/study5/ssh-student/WebContent/WEB-INF/views/edit.jsp ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ taglib prefix="s" uri="/struts-tags" %>
3
+ <!DOCTYPE html>
4
+ <html lang="zh-CN">
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>编辑学生 - SSH整合</title>
8
+ <style>
9
+ * { margin: 0; padding: 0; box-sizing: border-box; }
10
+ body { font-family: '微软雅黑', Arial, sans-serif; background: #f0f2f5; }
11
+ .header { background: #4527a0; color: white; padding: 0 30px; height: 56px;
12
+ display: flex; align-items: center; justify-content: space-between; }
13
+ .header h1 { font-size: 18px; }
14
+ .header a { color: white; text-decoration: none; font-size: 14px; }
15
+ .container { max-width: 560px; margin: 40px auto; padding: 0 16px; }
16
+ .card { background: white; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.07); padding: 30px; }
17
+ .card-title { font-size: 18px; font-weight: bold; color: #333; margin-bottom: 24px; }
18
+ .form-row { margin-bottom: 18px; }
19
+ .form-row label { display: block; font-size: 13px; color: #555; margin-bottom: 6px; font-weight: 500; }
20
+ .form-row input[type=text],
21
+ .form-row input[type=number],
22
+ .form-row select {
23
+ width: 100%; padding: 9px 12px; border: 1px solid #ddd; border-radius: 6px;
24
+ font-size: 14px; font-family: inherit;
25
+ }
26
+ .form-row input:focus, .form-row select:focus {
27
+ outline: none; border-color: #4527a0; box-shadow: 0 0 0 2px rgba(69,39,160,.15);
28
+ }
29
+ .radio-group label { display: inline-block; margin-right: 20px; font-size: 14px; font-weight: normal; cursor: pointer; }
30
+ .radio-group input { margin-right: 4px; }
31
+ .error-msg { background: #fce4ec; color: #c62828; border-radius: 6px;
32
+ padding: 10px 14px; font-size: 13px; margin-bottom: 18px; }
33
+ .btn-row { display: flex; gap: 12px; margin-top: 8px; }
34
+ .btn { padding: 10px 28px; border-radius: 6px; font-size: 14px;
35
+ border: none; cursor: pointer; text-decoration: none; display: inline-block; }
36
+ .btn-primary { background: #4527a0; color: white; }
37
+ .btn-primary:hover { background: #311b92; }
38
+ .btn-cancel { background: #f5f5f5; color: #555; }
39
+ .btn-cancel:hover { background: #e0e0e0; }
40
+ .required { color: #c62828; }
41
+ .id-badge { display: inline-block; background: #ede7f6; color: #4527a0;
42
+ padding: 2px 10px; border-radius: 10px; font-size: 13px;
43
+ margin-left: 8px; font-weight: normal; }
44
+ </style>
45
+ </head>
46
+ <body>
47
+
48
+ <div class="header">
49
+ <h1>💜 学生信息管理系统(SSH整合)</h1>
50
+ <a href="<%= request.getContextPath() %>/student_list">← 返回列表</a>
51
+ </div>
52
+
53
+ <div class="container">
54
+ <div class="card">
55
+ <div class="card-title">
56
+ ✏ 编辑学生
57
+ <span class="id-badge">ID: <s:property value="student.id"/></span>
58
+ </div>
59
+
60
+ <s:if test="hasActionErrors()">
61
+ <div class="error-msg"><s:actionerror theme="simple"/></div>
62
+ </s:if>
63
+
64
+ <s:form action="student_edit" method="post" theme="simple">
65
+ <%-- 回传 id(隐藏域) --%>
66
+ <s:hidden name="student.id"/>
67
+
68
+ <div class="form-row">
69
+ <label>姓名 <span class="required">*</span></label>
70
+ <s:textfield name="student.name"
71
+ cssStyle="width:100%;padding:9px 12px;border:1px solid #ddd;border-radius:6px;font-size:14px;"
72
+ maxlength="50"/>
73
+ </div>
74
+
75
+ <div class="form-row">
76
+ <label>性别 <span class="required">*</span></label>
77
+ <div class="radio-group">
78
+ <s:radio name="student.gender" list="{'男','女'}" theme="simple"/>
79
+ </div>
80
+ </div>
81
+
82
+ <div class="form-row">
83
+ <label>年龄 <span class="required">*</span></label>
84
+ <s:textfield name="student.age"
85
+ cssStyle="width:100%;padding:9px 12px;border:1px solid #ddd;border-radius:6px;font-size:14px;"/>
86
+ </div>
87
+
88
+ <div class="form-row">
89
+ <label>专业 <span class="required">*</span></label>
90
+ <s:select name="student.major"
91
+ list="{'计算机','软件工程','信息管理','网络工程'}"
92
+ headerKey="" headerValue="-- 请选择专业 --"
93
+ cssStyle="width:100%;padding:9px 12px;border:1px solid #ddd;border-radius:6px;font-size:14px;"/>
94
+ </div>
95
+
96
+ <div class="form-row">
97
+ <label>成绩(0~100)<span class="required">*</span></label>
98
+ <s:textfield name="student.score"
99
+ cssStyle="width:100%;padding:9px 12px;border:1px solid #ddd;border-radius:6px;font-size:14px;"/>
100
+ </div>
101
+
102
+ <div class="btn-row">
103
+ <s:submit value="保存修改" cssClass="btn btn-primary" theme="simple"/>
104
+ <a href="<%= request.getContextPath() %>/student_list" class="btn btn-cancel">取消</a>
105
+ </div>
106
+ </s:form>
107
+ </div>
108
+ </div>
109
+ </body>
110
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/workspace/study5/ssh-student/WebContent/WEB-INF/views/list.jsp ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ taglib prefix="s" uri="/struts-tags" %>
3
+ <!DOCTYPE html>
4
+ <html lang="zh-CN">
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>学生管理 - SSH整合</title>
8
+ <style>
9
+ * { margin: 0; padding: 0; box-sizing: border-box; }
10
+ body { font-family: '微软雅黑', Arial, sans-serif; background: #f0f2f5; }
11
+ .header { background: #4527a0; color: white; padding: 0 30px; height: 56px;
12
+ display: flex; align-items: center; justify-content: space-between; }
13
+ .header h1 { font-size: 18px; }
14
+ .header span { font-size: 13px; opacity: .75; }
15
+ .container { max-width: 1000px; margin: 30px auto; padding: 0 16px; }
16
+ .arch-tip { background: #ede7f6; border-left: 4px solid #7e57c2; padding: 10px 14px;
17
+ border-radius: 0 6px 6px 0; font-size: 13px; color: #4527a0;
18
+ margin-bottom: 16px; }
19
+ .arch-tip code { background: #d1c4e9; padding: 1px 6px; border-radius: 3px;
20
+ font-family: Consolas, monospace; }
21
+ .toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
22
+ .toolbar h2 { font-size: 16px; color: #333; }
23
+ .summary { font-size: 13px; color: #888; }
24
+ .btn { display: inline-block; padding: 8px 20px; border-radius: 6px;
25
+ font-size: 14px; text-decoration: none; }
26
+ .btn-primary { background: #4527a0; color: white; }
27
+ .btn-primary:hover { background: #311b92; }
28
+ .btn-edit { background: #ede7f6; color: #4527a0; font-size: 13px; padding: 4px 12px; }
29
+ .btn-edit:hover { background: #d1c4e9; }
30
+ .btn-del { background: #fce4ec; color: #c62828; font-size: 13px; padding: 4px 12px; }
31
+ .btn-del:hover { background: #f8bbd0; }
32
+ .card { background: white; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.07); overflow: hidden; }
33
+ table { width: 100%; border-collapse: collapse; font-size: 14px; }
34
+ thead th { background: #ede7f6; color: #4527a0; padding: 12px 16px;
35
+ text-align: left; font-weight: 600; border-bottom: 2px solid #ce93d8; }
36
+ tbody td { padding: 11px 16px; border-bottom: 1px solid #f5f5f5; }
37
+ tbody tr:last-child td { border-bottom: none; }
38
+ tbody tr:hover td { background: #fafafa; }
39
+ .badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 12px; font-weight: bold; }
40
+ .grade-优秀 { background: #e8f5e9; color: #1b5e20; }
41
+ .grade-良好 { background: #e3f2fd; color: #0d47a1; }
42
+ .grade-中等 { background: #fff8e1; color: #e65100; }
43
+ .grade-及格 { background: #fce4ec; color: #880e4f; }
44
+ .grade-不及格 { background: #f3e5f5; color: #4a148c; }
45
+ .error-msg { background: #fce4ec; color: #c62828; padding: 10px 16px;
46
+ border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
47
+ .empty { text-align: center; padding: 40px; color: #aaa; font-size: 14px; }
48
+ .actions { display: flex; gap: 6px; }
49
+ </style>
50
+ </head>
51
+ <body>
52
+
53
+ <div class="header">
54
+ <h1>💜 学生信息管理系统(SSH整合)</h1>
55
+ <span>实验8:Spring + Struts2 + Hibernate</span>
56
+ </div>
57
+
58
+ <div class="container">
59
+
60
+ <div class="arch-tip">
61
+ 架构:<code>Struts2 Action</code> → <code>Spring Service (@Transactional)</code>
62
+ → <code>HibernateDaoSupport</code> → <code>SQL Server</code>
63
+ &nbsp;|&nbsp; Action 由 Spring IoC 注入 Service(<code>scope="prototype"</code>)
64
+ </div>
65
+
66
+ <!-- s:actionerror 显示 Action 中 addActionError 的错误 -->
67
+ <s:if test="hasActionErrors()">
68
+ <div class="error-msg">
69
+ <s:actionerror theme="simple"/>
70
+ </div>
71
+ </s:if>
72
+
73
+ <div class="toolbar">
74
+ <h2>学生列表
75
+ <span class="summary">(共 <s:property value="studentList.size()"/> 人)</span>
76
+ </h2>
77
+ <a href="<%= request.getContextPath() %>/student_toAdd" class="btn btn-primary">+ 添加学生</a>
78
+ </div>
79
+
80
+ <div class="card">
81
+ <s:if test="studentList == null || studentList.size() == 0">
82
+ <div class="empty">暂无学生数据,点击右上角"添加学生"按钮添加。</div>
83
+ </s:if>
84
+ <s:else>
85
+ <table>
86
+ <thead>
87
+ <tr>
88
+ <th>ID</th><th>姓名</th><th>性别</th><th>年龄</th><th>专业</th><th>成绩</th><th>等级</th><th>操作</th>
89
+ </tr>
90
+ </thead>
91
+ <tbody>
92
+ <s:iterator value="studentList" var="s">
93
+ <tr>
94
+ <td><s:property value="#s.id"/></td>
95
+ <td><b><s:property value="#s.name"/></b></td>
96
+ <td>
97
+ <s:if test="#s.gender == '男'">👨</s:if><s:else>👩</s:else>
98
+ <s:property value="#s.gender"/>
99
+ </td>
100
+ <td><s:property value="#s.age"/></td>
101
+ <td><s:property value="#s.major"/></td>
102
+ <td><s:property value="#s.score"/></td>
103
+ <td>
104
+ <span class="badge grade-<s:property value="#s.grade"/>">
105
+ <s:property value="#s.grade"/>
106
+ </span>
107
+ </td>
108
+ <td>
109
+ <div class="actions">
110
+ <a href="<%= request.getContextPath() %>/student_toEdit?id=<s:property value="#s.id"/>"
111
+ class="btn btn-edit">编辑</a>
112
+ <a href="<%= request.getContextPath() %>/student_delete?id=<s:property value="#s.id"/>"
113
+ class="btn btn-del"
114
+ onclick="return confirm('确定要删除学生「<s:property value="#s.name"/>」吗?')">删除</a>
115
+ </div>
116
+ </td>
117
+ </tr>
118
+ </s:iterator>
119
+ </tbody>
120
+ </table>
121
+ </s:else>
122
+ </div>
123
+
124
+ </div>
125
+ </body>
126
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/workspace/study5/ssh-student/WebContent/WEB-INF/web.xml ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xmlns="http://java.sun.com/xml/ns/javaee"
4
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
5
+ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
6
+ version="2.5">
7
+
8
+ <display-name>实验8 - SSH整合学生管理</display-name>
9
+
10
+ <!-- Spring IoC 容器:加载 applicationContext.xml -->
11
+ <listener>
12
+ <listener-class>
13
+ org.springframework.web.context.ContextLoaderListener
14
+ </listener-class>
15
+ </listener>
16
+ <context-param>
17
+ <param-name>contextConfigLocation</param-name>
18
+ <param-value>classpath:applicationContext.xml</param-value>
19
+ </context-param>
20
+
21
+ <!-- UTF-8 编码过滤器 -->
22
+ <filter>
23
+ <filter-name>encodingFilter</filter-name>
24
+ <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
25
+ <init-param>
26
+ <param-name>encoding</param-name>
27
+ <param-value>UTF-8</param-value>
28
+ </init-param>
29
+ <init-param>
30
+ <param-name>forceEncoding</param-name>
31
+ <param-value>true</param-value>
32
+ </init-param>
33
+ </filter>
34
+ <filter-mapping>
35
+ <filter-name>encodingFilter</filter-name>
36
+ <url-pattern>/*</url-pattern>
37
+ </filter-mapping>
38
+
39
+ <!-- Struts2 核心过滤器(通过 Spring 创建 Action) -->
40
+ <filter>
41
+ <filter-name>struts2</filter-name>
42
+ <filter-class>
43
+ org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
44
+ </filter-class>
45
+ </filter>
46
+ <filter-mapping>
47
+ <filter-name>struts2</filter-name>
48
+ <url-pattern>/*</url-pattern>
49
+ </filter-mapping>
50
+
51
+ <welcome-file-list>
52
+ <welcome-file>index.jsp</welcome-file>
53
+ </welcome-file-list>
54
+
55
+ </web-app>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/README.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 实验一:开发环境配置及一个简单应用
2
+
3
+ ## 一、实验目的
4
+ 1. 掌握 Java EE 开发环境的配置方法
5
+ 2. 熟悉 MyEclipse 开发环境的使用
6
+
7
+ ## 二、实验内容
8
+ 1. 编写一个简单的 Servlet 应用程序,实现用户登录功能,并在另一页中显示输入的用户名和密码
9
+ 2. 编写一个简单的 JSP 应用程序,实现用户登录功能,并在另一页中显示输入的用户名和密码
10
+ 3. 编写一个 Struts 2 应用程序,实现简单的用户登录功能,并部署运行
11
+
12
+ ## 三、开发环境
13
+ - JDK 1.6+ (本实验使用 JDK 1.8)
14
+ - Tomcat 6.0+
15
+ - MyEclipse 8.6+ 或 Eclipse + 插件
16
+
17
+ ## 四、项目结构
18
+ ```
19
+ study1/
20
+ ├── README.md
21
+ ├── servlet-login/ # Servlet 登录示例
22
+ │ ├── src/
23
+ │ │ └── com/example/
24
+ │ │ ├── LoginServlet.java
25
+ │ │ └── SuccessServlet.java
26
+ │ └── WebContent/
27
+ │ ├── login.html
28
+ │ └── success.jsp
29
+ ├── jsp-login/ # JSP 登录示例
30
+ │ └── WebContent/
31
+ │ ├── login.jsp
32
+ │ └── success.jsp
33
+ └── struts2-login/ # Struts 2 登录示例
34
+ ├── src/
35
+ │ └── com/example/
36
+ │ ├── LoginAction.java
37
+ │ └── struts.xml
38
+ └── WebContent/
39
+ ├── login.jsp
40
+ └── success.jsp
41
+ ```
42
+
43
+ ## 五、环境配置步骤
44
+
45
+ ### 1. 安装 JDK
46
+ - 默认安装路径:`C:\Program Files\Java\jdk1.6.0_27`
47
+ - 当前系统已安装:OpenJDK 1.8.0_302
48
+
49
+ ### 2. 设置环境变量
50
+ - **JAVA_HOME**: `C:\Program Files\Java\jdk1.6.0_27`
51
+ - **Path**: 添加 `;%JAVA_HOME%\bin`
52
+ - **CLASSPATH**: `.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar`
53
+
54
+ ### 3. 配置 Tomcat
55
+ - 安装路径:`C:\Program Files\Apache Software Foundation\Tomcat 6.0`
56
+ - 在 MyEclipse 中配置 Tomcat 服务器
57
+
58
+ ### 4. 配置 MyEclipse
59
+ - Windows → Preferences → Java → Installed JREs → Add JDK
60
+ - Windows → Preferences → MyEclipse → Servers → Tomcat 6.0 → Enable
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/jsp-login/WebContent/login.jsp ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <!DOCTYPE html>
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <title>用户登录 - JSP 示例</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ background-color: #f0f0f0;
11
+ display: flex;
12
+ justify-content: center;
13
+ align-items: center;
14
+ height: 100vh;
15
+ margin: 0;
16
+ }
17
+ .login-container {
18
+ background-color: white;
19
+ padding: 30px;
20
+ border-radius: 8px;
21
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
22
+ width: 350px;
23
+ }
24
+ h2 {
25
+ text-align: center;
26
+ color: #333;
27
+ margin-bottom: 25px;
28
+ }
29
+ .form-group {
30
+ margin-bottom: 20px;
31
+ }
32
+ label {
33
+ display: block;
34
+ margin-bottom: 5px;
35
+ color: #555;
36
+ font-weight: bold;
37
+ }
38
+ input[type="text"],
39
+ input[type="password"] {
40
+ width: 100%;
41
+ padding: 10px;
42
+ border: 1px solid #ddd;
43
+ border-radius: 4px;
44
+ box-sizing: border-box;
45
+ font-size: 14px;
46
+ }
47
+ input[type="submit"] {
48
+ width: 100%;
49
+ padding: 12px;
50
+ background-color: #2196F3;
51
+ color: white;
52
+ border: none;
53
+ border-radius: 4px;
54
+ cursor: pointer;
55
+ font-size: 16px;
56
+ }
57
+ input[type="submit"]:hover {
58
+ background-color: #1976D2;
59
+ }
60
+ .error {
61
+ color: red;
62
+ text-align: center;
63
+ margin-bottom: 15px;
64
+ }
65
+ </style>
66
+ </head>
67
+ <body>
68
+ <div class="login-container">
69
+ <h2>用户登录 (JSP)</h2>
70
+ <%
71
+ String error = (String) request.getAttribute("error");
72
+ if (error != null) {
73
+ %>
74
+ <div class="error"><%= error %></div>
75
+ <% } %>
76
+ <form action="success.jsp" method="post">
77
+ <div class="form-group">
78
+ <label for="username">用户名:</label>
79
+ <input type="text" id="username" name="username" required placeholder="请输入用户名">
80
+ </div>
81
+ <div class="form-group">
82
+ <label for="password">密码:</label>
83
+ <input type="password" id="password" name="password" required placeholder="请输入密码">
84
+ </div>
85
+ <div class="form-group">
86
+ <input type="submit" value="登录">
87
+ </div>
88
+ </form>
89
+ </div>
90
+ </body>
91
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/jsp-login/WebContent/success.jsp ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%
3
+ // 处理登录逻辑
4
+ request.setCharacterEncoding("UTF-8");
5
+ String username = request.getParameter("username");
6
+ String password = request.getParameter("password");
7
+
8
+ // 将数据存入 session
9
+ session.setAttribute("username", username);
10
+ session.setAttribute("password", password);
11
+ %>
12
+ <!DOCTYPE html>
13
+ <html>
14
+ <head>
15
+ <meta charset="UTF-8">
16
+ <title>登录成功 - JSP 示例</title>
17
+ <style>
18
+ body {
19
+ font-family: Arial, sans-serif;
20
+ background-color: #f0f0f0;
21
+ display: flex;
22
+ justify-content: center;
23
+ align-items: center;
24
+ height: 100vh;
25
+ margin: 0;
26
+ }
27
+ .success-container {
28
+ background-color: white;
29
+ padding: 40px;
30
+ border-radius: 8px;
31
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
32
+ text-align: center;
33
+ max-width: 400px;
34
+ }
35
+ h2 {
36
+ color: #2196F3;
37
+ margin-bottom: 20px;
38
+ }
39
+ .info {
40
+ background-color: #f9f9f9;
41
+ padding: 20px;
42
+ border-radius: 4px;
43
+ margin: 20px 0;
44
+ text-align: left;
45
+ }
46
+ .info p {
47
+ margin: 10px 0;
48
+ color: #333;
49
+ }
50
+ .info strong {
51
+ color: #555;
52
+ }
53
+ a {
54
+ display: inline-block;
55
+ margin-top: 20px;
56
+ padding: 10px 30px;
57
+ background-color: #2196F3;
58
+ color: white;
59
+ text-decoration: none;
60
+ border-radius: 4px;
61
+ }
62
+ a:hover {
63
+ background-color: #1976D2;
64
+ }
65
+ </style>
66
+ </head>
67
+ <body>
68
+ <div class="success-container">
69
+ <h2>✓ 登录成功</h2>
70
+ <div class="info">
71
+ <p><strong>欢迎回来!</strong></p>
72
+ <p>您输入的用户信息如下:</p>
73
+ <hr style="border: none; border-top: 1px solid #ddd; margin: 15px 0;">
74
+ <p><strong>用户名:</strong> <%= session.getAttribute("username") %></p>
75
+ <p><strong>密码:</strong> <%= session.getAttribute("password") %></p>
76
+ </div>
77
+ <p style="color: #888; font-size: 12px; margin-top: 20px;">
78
+ 这是 JSP 处理登录后的结果展示页面
79
+ </p>
80
+ <a href="login.jsp">返回登录</a>
81
+ </div>
82
+ </body>
83
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/servlet-login/WebContent/WEB-INF/web.xml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xmlns="http://java.sun.com/xml/ns/javaee"
4
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
5
+ http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
6
+ id="WebApp_ID" version="3.0">
7
+
8
+ <display-name>Servlet Login Example</display-name>
9
+
10
+ <welcome-file-list>
11
+ <welcome-file>login.html</welcome-file>
12
+ </welcome-file-list>
13
+
14
+ <servlet>
15
+ <description>This is the login servlet</description>
16
+ <display-name>LoginServlet</display-name>
17
+ <servlet-name>LoginServlet</servlet-name>
18
+ <servlet-class>com.example.LoginServlet</servlet-class>
19
+ </servlet>
20
+
21
+ <servlet-mapping>
22
+ <servlet-name>LoginServlet</servlet-name>
23
+ <url-pattern>/LoginServlet</url-pattern>
24
+ </servlet-mapping>
25
+
26
+ <session-config>
27
+ <session-timeout>30</session-timeout>
28
+ </session-config>
29
+
30
+ </web-app>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/servlet-login/WebContent/login.html ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>用户登录 - Servlet 示例</title>
6
+ <style>
7
+ body {
8
+ font-family: Arial, sans-serif;
9
+ background-color: #f0f0f0;
10
+ display: flex;
11
+ justify-content: center;
12
+ align-items: center;
13
+ height: 100vh;
14
+ margin: 0;
15
+ }
16
+ .login-container {
17
+ background-color: white;
18
+ padding: 30px;
19
+ border-radius: 8px;
20
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
21
+ width: 350px;
22
+ }
23
+ h2 {
24
+ text-align: center;
25
+ color: #333;
26
+ margin-bottom: 25px;
27
+ }
28
+ .form-group {
29
+ margin-bottom: 20px;
30
+ }
31
+ label {
32
+ display: block;
33
+ margin-bottom: 5px;
34
+ color: #555;
35
+ font-weight: bold;
36
+ }
37
+ input[type="text"],
38
+ input[type="password"] {
39
+ width: 100%;
40
+ padding: 10px;
41
+ border: 1px solid #ddd;
42
+ border-radius: 4px;
43
+ box-sizing: border-box;
44
+ font-size: 14px;
45
+ }
46
+ input[type="submit"] {
47
+ width: 100%;
48
+ padding: 12px;
49
+ background-color: #4CAF50;
50
+ color: white;
51
+ border: none;
52
+ border-radius: 4px;
53
+ cursor: pointer;
54
+ font-size: 16px;
55
+ }
56
+ input[type="submit"]:hover {
57
+ background-color: #45a049;
58
+ }
59
+ .error {
60
+ color: red;
61
+ text-align: center;
62
+ margin-bottom: 15px;
63
+ }
64
+ </style>
65
+ </head>
66
+ <body>
67
+ <div class="login-container">
68
+ <h2>用户登录</h2>
69
+ <form action="LoginServlet" method="post">
70
+ <div class="form-group">
71
+ <label for="username">用户名:</label>
72
+ <input type="text" id="username" name="username" required placeholder="请输入用户名">
73
+ </div>
74
+ <div class="form-group">
75
+ <label for="password">密码:</label>
76
+ <input type="password" id="password" name="password" required placeholder="请输入密码">
77
+ </div>
78
+ <div class="form-group">
79
+ <input type="submit" value="登录">
80
+ </div>
81
+ </form>
82
+ </div>
83
+ </body>
84
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/servlet-login/WebContent/success.jsp ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ page session="true" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>登录成功 - Servlet 示例</title>
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ background-color: #f0f0f0;
12
+ display: flex;
13
+ justify-content: center;
14
+ align-items: center;
15
+ height: 100vh;
16
+ margin: 0;
17
+ }
18
+ .success-container {
19
+ background-color: white;
20
+ padding: 40px;
21
+ border-radius: 8px;
22
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
23
+ text-align: center;
24
+ max-width: 400px;
25
+ }
26
+ h2 {
27
+ color: #4CAF50;
28
+ margin-bottom: 20px;
29
+ }
30
+ .info {
31
+ background-color: #f9f9f9;
32
+ padding: 20px;
33
+ border-radius: 4px;
34
+ margin: 20px 0;
35
+ text-align: left;
36
+ }
37
+ .info p {
38
+ margin: 10px 0;
39
+ color: #333;
40
+ }
41
+ .info strong {
42
+ color: #555;
43
+ }
44
+ a {
45
+ display: inline-block;
46
+ margin-top: 20px;
47
+ padding: 10px 30px;
48
+ background-color: #4CAF50;
49
+ color: white;
50
+ text-decoration: none;
51
+ border-radius: 4px;
52
+ }
53
+ a:hover {
54
+ background-color: #45a049;
55
+ }
56
+ </style>
57
+ </head>
58
+ <body>
59
+ <div class="success-container">
60
+ <h2>✓ 登录成功</h2>
61
+ <div class="info">
62
+ <p><strong>欢迎回来!</strong></p>
63
+ <p>您输入的用户信息如下:</p>
64
+ <hr style="border: none; border-top: 1px solid #ddd; margin: 15px 0;">
65
+ <p><strong>用户名:</strong> <%= session.getAttribute("username") %></p>
66
+ <p><strong>密码:</strong> <%= session.getAttribute("password") %></p>
67
+ </div>
68
+ <p style="color: #888; font-size: 12px; margin-top: 20px;">
69
+ 这是 Servlet 处理登录后的结果展示页面
70
+ </p>
71
+ <a href="login.html">返回登录</a>
72
+ </div>
73
+ </body>
74
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/servlet-login/src/com/example/LoginServlet.java ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package com.example;
2
+
3
+ import java.io.IOException;
4
+ import javax.servlet.ServletException;
5
+ import javax.servlet.http.HttpServlet;
6
+ import javax.servlet.http.HttpServletRequest;
7
+ import javax.servlet.http.HttpServletResponse;
8
+ import javax.servlet.http.HttpSession;
9
+
10
+ /**
11
+ * Servlet 实现用户登录功能
12
+ */
13
+ public class LoginServlet extends HttpServlet {
14
+
15
+ public LoginServlet() {
16
+ super();
17
+ }
18
+
19
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
20
+ throws ServletException, IOException {
21
+ doPost(request, response);
22
+ }
23
+
24
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
25
+ throws ServletException, IOException {
26
+ // 设置请求编码
27
+ request.setCharacterEncoding("UTF-8");
28
+ response.setContentType("text/html;charset=UTF-8");
29
+
30
+ // 获取表单参数
31
+ String username = request.getParameter("username");
32
+ String password = request.getParameter("password");
33
+
34
+ // 简单验证(实际应用中应该查询数据库)
35
+ if (username != null && password != null && !username.trim().isEmpty()) {
36
+ // 将用户信息存入 Session
37
+ HttpSession session = request.getSession();
38
+ session.setAttribute("username", username);
39
+ session.setAttribute("password", password);
40
+
41
+ // 重定向到成功页面
42
+ response.sendRedirect("success.jsp");
43
+ } else {
44
+ // 验证失败,返回登录页面
45
+ request.setAttribute("error", "用户名不能为空!");
46
+ request.getRequestDispatcher("/login.html").forward(request, response);
47
+ }
48
+ }
49
+ }
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/struts2-login/WebContent/WEB-INF/web.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xmlns="http://java.sun.com/xml/ns/javaee"
4
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
5
+ http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
6
+ id="WebApp_ID" version="3.0">
7
+
8
+ <display-name>Struts 2 Login Example</display-name>
9
+
10
+ <welcome-file-list>
11
+ <welcome-file>login.jsp</welcome-file>
12
+ </welcome-file-list>
13
+
14
+ <!-- Struts 2 Filter -->
15
+ <filter>
16
+ <filter-name>struts2</filter-name>
17
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
18
+ </filter>
19
+
20
+ <filter-mapping>
21
+ <filter-name>struts2</filter-name>
22
+ <url-pattern>/*</url-pattern>
23
+ </filter-mapping>
24
+
25
+ </web-app>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/struts2-login/WebContent/login.jsp ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ taglib prefix="s" uri="/struts-tags" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>用户登录 - Struts 2 示例</title>
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ background-color: #f0f0f0;
12
+ display: flex;
13
+ justify-content: center;
14
+ align-items: center;
15
+ height: 100vh;
16
+ margin: 0;
17
+ }
18
+ .login-container {
19
+ background-color: white;
20
+ padding: 30px;
21
+ border-radius: 8px;
22
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
23
+ width: 350px;
24
+ }
25
+ h2 {
26
+ text-align: center;
27
+ color: #333;
28
+ margin-bottom: 25px;
29
+ }
30
+ .form-group {
31
+ margin-bottom: 20px;
32
+ }
33
+ label {
34
+ display: block;
35
+ margin-bottom: 5px;
36
+ color: #555;
37
+ font-weight: bold;
38
+ }
39
+ input[type="text"],
40
+ input[type="password"] {
41
+ width: 100%;
42
+ padding: 10px;
43
+ border: 1px solid #ddd;
44
+ border-radius: 4px;
45
+ box-sizing: border-box;
46
+ font-size: 14px;
47
+ }
48
+ input[type="submit"] {
49
+ width: 100%;
50
+ padding: 12px;
51
+ background-color: #9C27B0;
52
+ color: white;
53
+ border: none;
54
+ border-radius: 4px;
55
+ cursor: pointer;
56
+ font-size: 16px;
57
+ }
58
+ input[type="submit"]:hover {
59
+ background-color: #7B1FA2;
60
+ }
61
+ .error {
62
+ color: red;
63
+ text-align: center;
64
+ margin-bottom: 15px;
65
+ }
66
+ .field-error {
67
+ color: red;
68
+ font-size: 12px;
69
+ margin-top: 5px;
70
+ }
71
+ </style>
72
+ </head>
73
+ <body>
74
+ <div class="login-container">
75
+ <h2>用户登录 (Struts 2)</h2>
76
+ <s:form action="login" method="post" theme="simple">
77
+ <div class="form-group">
78
+ <label for="username">用户名:</label>
79
+ <s:textfield name="username" id="username" cssStyle="width:100%;padding:10px;border:1px solid #ddd;border-radius:4px;"
80
+ placeholder="请输入用户名"/>
81
+ <s:fielderror fieldName="username" cssClass="field-error"/>
82
+ </div>
83
+ <div class="form-group">
84
+ <label for="password">密码:</label>
85
+ <s:password name="password" id="password" cssStyle="width:100%;padding:10px;border:1px solid #ddd;border-radius:4px;"
86
+ placeholder="请输入密码"/>
87
+ <s:fielderror fieldName="password" cssClass="field-error"/>
88
+ </div>
89
+ <div class="form-group">
90
+ <s:submit value="登录" cssStyle="width:100%;padding:12px;background-color:#9C27B0;color:white;border:none;border-radius:4px;cursor:pointer;font-size:16px;"/>
91
+ </div>
92
+ </s:form>
93
+ </div>
94
+ </body>
95
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/struts2-login/WebContent/success.jsp ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ taglib prefix="s" uri="/struts-tags" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>登录成功 - Struts 2 示例</title>
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ background-color: #f0f0f0;
12
+ display: flex;
13
+ justify-content: center;
14
+ align-items: center;
15
+ height: 100vh;
16
+ margin: 0;
17
+ }
18
+ .success-container {
19
+ background-color: white;
20
+ padding: 40px;
21
+ border-radius: 8px;
22
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
23
+ text-align: center;
24
+ max-width: 400px;
25
+ }
26
+ h2 {
27
+ color: #9C27B0;
28
+ margin-bottom: 20px;
29
+ }
30
+ .info {
31
+ background-color: #f9f9f9;
32
+ padding: 20px;
33
+ border-radius: 4px;
34
+ margin: 20px 0;
35
+ text-align: left;
36
+ }
37
+ .info p {
38
+ margin: 10px 0;
39
+ color: #333;
40
+ }
41
+ .info strong {
42
+ color: #555;
43
+ }
44
+ a {
45
+ display: inline-block;
46
+ margin-top: 20px;
47
+ padding: 10px 30px;
48
+ background-color: #9C27B0;
49
+ color: white;
50
+ text-decoration: none;
51
+ border-radius: 4px;
52
+ }
53
+ a:hover {
54
+ background-color: #7B1FA2;
55
+ }
56
+ </style>
57
+ </head>
58
+ <body>
59
+ <div class="success-container">
60
+ <h2>✓ 登录成功</h2>
61
+ <div class="info">
62
+ <p><strong>欢迎回来!</strong></p>
63
+ <p>您输入的用户信息如下:</p>
64
+ <hr style="border: none; border-top: 1px solid #ddd; margin: 15px 0;">
65
+ <p><strong>用户名:</strong> <s:property value="username"/></p>
66
+ <p><strong>密码:</strong> <s:property value="password"/></p>
67
+ </div>
68
+ <p style="color: #888; font-size: 12px; margin-top: 20px;">
69
+ 这是 Struts 2 处理登录后的结果展示页面
70
+ </p>
71
+ <a href="login.jsp">返回登录</a>
72
+ </div>
73
+ </body>
74
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/struts2-login/src/com/example/LoginAction.java ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package com.example;
2
+
3
+ import com.opensymphony.xwork2.ActionSupport;
4
+
5
+ /**
6
+ * Struts 2 登录 Action
7
+ */
8
+ public class LoginAction extends ActionSupport {
9
+
10
+ private String username;
11
+ private String password;
12
+
13
+ public LoginAction() {
14
+ super();
15
+ }
16
+
17
+ // 执行登录逻辑
18
+ public String execute() throws Exception {
19
+ // 简单验证
20
+ if (username != null && !username.trim().isEmpty() &&
21
+ password != null && !password.trim().isEmpty()) {
22
+ return SUCCESS;
23
+ } else {
24
+ if (username == null || username.trim().isEmpty()) {
25
+ addFieldError("username", "用户名不能为空");
26
+ }
27
+ if (password == null || password.trim().isEmpty()) {
28
+ addFieldError("password", "密码不能为空");
29
+ }
30
+ return INPUT;
31
+ }
32
+ }
33
+
34
+ // Getter 和 Setter
35
+ public String getUsername() {
36
+ return username;
37
+ }
38
+
39
+ public void setUsername(String username) {
40
+ this.username = username;
41
+ }
42
+
43
+ public String getPassword() {
44
+ return password;
45
+ }
46
+
47
+ public void setPassword(String password) {
48
+ this.password = password;
49
+ }
50
+ }
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study1/struts2-login/src/struts.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE struts PUBLIC
3
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
4
+ "http://struts.apache.org/dtds/struts-2.0.dtd">
5
+
6
+ <struts>
7
+ <package name="default" namespace="/" extends="struts-default">
8
+
9
+ <action name="login" class="com.example.LoginAction">
10
+ <result name="success">/success.jsp</result>
11
+ <result name="input">/login.jsp</result>
12
+ </action>
13
+
14
+ </package>
15
+ </struts>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/README.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 实验二:JSP 应用
2
+
3
+ ## 一、实验目的
4
+ 1. 熟练掌握 JSP 基本语法及其应用
5
+ 2. 掌握常用 JSP 内置对象及其应用
6
+ 3. 熟悉 JavaBean 在 JSP 中的使用
7
+
8
+ ## 二、实验内容
9
+ 实现一个网上商店 netshop,具有以下功能:
10
+ 1. 建立 Web 应用 netshop
11
+ 2. 实现用户登录、注册功能
12
+
13
+ ### 页面设计要求:
14
+ 1. 完成首页、用户登录、注册功能
15
+ 2. 首页实现商品浏览、登录用户计数(采用 application 对象)等功能;包含按钮:登录、注册
16
+ 3. 登录页中输入用户名、密码,当密码为空时提示错误
17
+ 4. 使用 session 对象保存登录用户信息
18
+ 5. 使用 application 对象统计在线用户数
19
+
20
+ ## 三、项目结构
21
+ ```
22
+ study2/
23
+ ├── README.md
24
+ ├── src/
25
+ │ └── com/netshop/
26
+ │ ├── User.java # 用户 JavaBean
27
+ │ └── Product.java # 商品 JavaBean
28
+ └── WebContent/
29
+ ├── index.jsp # 首页
30
+ ├── login.jsp # 登录页
31
+ ├── register.jsp # 注册页
32
+ ├── success.jsp # 登录成功页
33
+ └── WEB-INF/
34
+ └── web.xml
35
+ ```
36
+
37
+ ## 四、技术要点
38
+ - **JSP 内置对象**:request, response, session, application, out
39
+ - **JavaBean**:封装用户和商品数据
40
+ - **作用域**:pageScope, requestScope, sessionScope, applicationScope
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/WebContent/WEB-INF/web.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xmlns="http://java.sun.com/xml/ns/javaee"
4
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
5
+ http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
6
+ id="WebApp_ID" version="3.0">
7
+
8
+ <display-name>NetShop - JSP Example</display-name>
9
+
10
+ <welcome-file-list>
11
+ <welcome-file>index.jsp</welcome-file>
12
+ </welcome-file-list>
13
+
14
+ </web-app>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/WebContent/index.jsp ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ page import="java.util.*, com.netshop.*" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>NetShop 网上商店 - 首页</title>
8
+ <style>
9
+ * { margin: 0; padding: 0; box-sizing: border-box; }
10
+ body { font-family: Arial, sans-serif; background-color: #f5f5f5; }
11
+
12
+ /* 顶部导航 */
13
+ .header {
14
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
15
+ color: white;
16
+ padding: 15px 30px;
17
+ display: flex;
18
+ justify-content: space-between;
19
+ align-items: center;
20
+ }
21
+ .header h1 { font-size: 24px; }
22
+ .header .nav a {
23
+ color: white;
24
+ text-decoration: none;
25
+ margin-left: 20px;
26
+ padding: 8px 16px;
27
+ border-radius: 4px;
28
+ background: rgba(255,255,255,0.2);
29
+ }
30
+ .header .nav a:hover { background: rgba(255,255,255,0.3); }
31
+
32
+ /* 统计信息 */
33
+ .stats {
34
+ background: white;
35
+ padding: 15px 30px;
36
+ display: flex;
37
+ justify-content: space-around;
38
+ border-bottom: 1px solid #eee;
39
+ }
40
+ .stat-item { text-align: center; }
41
+ .stat-item .number { font-size: 24px; font-weight: bold; color: #667eea; }
42
+ .stat-item .label { color: #666; font-size: 14px; }
43
+
44
+ /* 商品列表 */
45
+ .products {
46
+ padding: 30px;
47
+ display: grid;
48
+ grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
49
+ gap: 20px;
50
+ max-width: 1200px;
51
+ margin: 0 auto;
52
+ }
53
+ .product-card {
54
+ background: white;
55
+ border-radius: 8px;
56
+ overflow: hidden;
57
+ box-shadow: 0 2px 8px rgba(0,0,0,0.1);
58
+ transition: transform 0.3s;
59
+ }
60
+ .product-card:hover { transform: translateY(-5px); }
61
+ .product-card .image {
62
+ height: 180px;
63
+ background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
64
+ display: flex;
65
+ align-items: center;
66
+ justify-content: center;
67
+ font-size: 48px;
68
+ color: #667eea;
69
+ }
70
+ .product-card .info { padding: 15px; }
71
+ .product-card .name { font-size: 16px; font-weight: bold; margin-bottom: 8px; }
72
+ .product-card .price { color: #e74c3c; font-size: 18px; font-weight: bold; }
73
+ .product-card .desc { color: #666; font-size: 13px; margin: 8px 0; }
74
+
75
+ /* 页脚 */
76
+ .footer {
77
+ background: #333;
78
+ color: white;
79
+ text-align: center;
80
+ padding: 20px;
81
+ margin-top: 40px;
82
+ }
83
+ </style>
84
+ </head>
85
+ <body>
86
+ <%
87
+ // 初始化商品列表(首次访问时)
88
+ List<Product> products = (List<Product>) application.getAttribute("products");
89
+ if (products == null) {
90
+ products = new ArrayList<>();
91
+ products.add(new Product(1, "iPhone 15", 7999.00));
92
+ products.add(new Product(2, "MacBook Pro", 14999.00));
93
+ products.add(new Product(3, "AirPods Pro", 1899.00));
94
+ products.add(new Product(4, "iPad Air", 4799.00));
95
+ products.add(new Product(5, "Apple Watch", 3199.00));
96
+ products.add(new Product(6, "HomePod", 2299.00));
97
+ application.setAttribute("products", products);
98
+ }
99
+
100
+ // 在线用户计数
101
+ Integer onlineCount = (Integer) application.getAttribute("onlineCount");
102
+ if (onlineCount == null) {
103
+ onlineCount = 0;
104
+ }
105
+ onlineCount++;
106
+ application.setAttribute("onlineCount", onlineCount);
107
+
108
+ // 检查用户是否登录
109
+ User currentUser = (User) session.getAttribute("currentUser");
110
+ %>
111
+
112
+ <div class="header">
113
+ <h1>🛒 NetShop 网上商店</h1>
114
+ <div class="nav">
115
+ <% if (currentUser != null) { %>
116
+ <span>欢迎,<%= currentUser.getUsername() %></span>
117
+ <a href="logout.jsp">退出登录</a>
118
+ <% } else { %>
119
+ <a href="login.jsp">登录</a>
120
+ <a href="register.jsp">注册</a>
121
+ <% } %>
122
+ </div>
123
+ </div>
124
+
125
+ <div class="stats">
126
+ <div class="stat-item">
127
+ <div class="number"><%= onlineCount %></div>
128
+ <div class="label">当前在线用户</div>
129
+ </div>
130
+ <div class="stat-item">
131
+ <div class="number"><%= products.size() %></div>
132
+ <div class="label">商品总数</div>
133
+ </div>
134
+ <div class="stat-item">
135
+ <div class="number">
136
+ <%= application.getAttribute("visitCount") == null ? 1 : (Integer)application.getAttribute("visitCount") + 1 %>
137
+ </div>
138
+ <div class="label">总访问量</div>
139
+ </div>
140
+ </div>
141
+
142
+ <%
143
+ // 更新总访问量
144
+ Integer visitCount = (Integer) application.getAttribute("visitCount");
145
+ if (visitCount == null) {
146
+ visitCount = 0;
147
+ }
148
+ visitCount++;
149
+ application.setAttribute("visitCount", visitCount);
150
+ %>
151
+
152
+ <div class="products">
153
+ <% for (Product p : products) { %>
154
+ <div class="product-card">
155
+ <div class="image">📦</div>
156
+ <div class="info">
157
+ <div class="name"><%= p.getName() %></div>
158
+ <div class="desc">高品质数码产品</div>
159
+ <div class="price">¥<%= String.format("%.2f", p.getPrice()) %></div>
160
+ </div>
161
+ </div>
162
+ <% } %>
163
+ </div>
164
+
165
+ <div class="footer">
166
+ <p>&copy; 2024 NetShop 网上商店 - JSP 实验项目</p>
167
+ </div>
168
+ </body>
169
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/WebContent/login.jsp ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ page import="com.netshop.User" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>用户登录 - NetShop</title>
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
12
+ display: flex;
13
+ justify-content: center;
14
+ align-items: center;
15
+ height: 100vh;
16
+ margin: 0;
17
+ }
18
+ .login-container {
19
+ background: white;
20
+ padding: 40px;
21
+ border-radius: 10px;
22
+ box-shadow: 0 10px 40px rgba(0,0,0,0.2);
23
+ width: 400px;
24
+ }
25
+ h2 {
26
+ text-align: center;
27
+ color: #333;
28
+ margin-bottom: 30px;
29
+ }
30
+ .form-group {
31
+ margin-bottom: 20px;
32
+ }
33
+ label {
34
+ display: block;
35
+ margin-bottom: 8px;
36
+ color: #555;
37
+ font-weight: bold;
38
+ }
39
+ input[type="text"],
40
+ input[type="password"] {
41
+ width: 100%;
42
+ padding: 12px;
43
+ border: 2px solid #ddd;
44
+ border-radius: 6px;
45
+ font-size: 14px;
46
+ transition: border-color 0.3s;
47
+ }
48
+ input:focus {
49
+ outline: none;
50
+ border-color: #667eea;
51
+ }
52
+ input[type="submit"] {
53
+ width: 100%;
54
+ padding: 14px;
55
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
56
+ color: white;
57
+ border: none;
58
+ border-radius: 6px;
59
+ cursor: pointer;
60
+ font-size: 16px;
61
+ font-weight: bold;
62
+ }
63
+ input[type="submit"]:hover {
64
+ opacity: 0.9;
65
+ }
66
+ .error {
67
+ color: #e74c3c;
68
+ background: #fde8e8;
69
+ padding: 10px;
70
+ border-radius: 4px;
71
+ margin-bottom: 20px;
72
+ text-align: center;
73
+ }
74
+ .links {
75
+ text-align: center;
76
+ margin-top: 20px;
77
+ }
78
+ .links a {
79
+ color: #667eea;
80
+ text-decoration: none;
81
+ }
82
+ .links a:hover {
83
+ text-decoration: underline;
84
+ }
85
+ </style>
86
+ </head>
87
+ <body>
88
+ <div class="login-container">
89
+ <h2>🔐 用户登录</h2>
90
+
91
+ <%
92
+ String error = (String) request.getAttribute("error");
93
+ if (error != null) {
94
+ %>
95
+ <div class="error"><%= error %></div>
96
+ <% } %>
97
+
98
+ <form action="login.jsp" method="post">
99
+ <div class="form-group">
100
+ <label for="username">用户名</label>
101
+ <input type="text" id="username" name="username" required placeholder="请输入用户名">
102
+ </div>
103
+ <div class="form-group">
104
+ <label for="password">密码</label>
105
+ <input type="password" id="password" name="password" required placeholder="请输入密码">
106
+ </div>
107
+ <div class="form-group">
108
+ <input type="submit" value="登 录">
109
+ </div>
110
+ </form>
111
+
112
+ <div class="links">
113
+ <p>还没有账号?<a href="register.jsp">立即注册</a></p>
114
+ <p><a href="index.jsp">返回首页</a></p>
115
+ </div>
116
+ </div>
117
+
118
+ <%
119
+ // 处理登录请求
120
+ if ("POST".equalsIgnoreCase(request.getMethod())) {
121
+ String username = request.getParameter("username");
122
+ String password = request.getParameter("password");
123
+
124
+ // 验证
125
+ if (username == null || username.trim().isEmpty()) {
126
+ request.setAttribute("error", "用户名不能为空!");
127
+ } else if (password == null || password.trim().isEmpty()) {
128
+ request.setAttribute("error", "密码不能为空!");
129
+ } else {
130
+ // 简单验证(实际应该查询数据库)
131
+ // 这里模拟登录成功
132
+ User user = new User(username, password);
133
+ session.setAttribute("currentUser", user);
134
+
135
+ // 重定向到首页
136
+ response.sendRedirect("index.jsp");
137
+ return;
138
+ }
139
+ }
140
+ %>
141
+ </body>
142
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/WebContent/logout.jsp ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <!DOCTYPE html>
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <title>退出登录 - NetShop</title>
7
+ <meta http-equiv="refresh" content="2;url=index.jsp">
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
12
+ display: flex;
13
+ justify-content: center;
14
+ align-items: center;
15
+ height: 100vh;
16
+ margin: 0;
17
+ }
18
+ .message {
19
+ background: white;
20
+ padding: 40px;
21
+ border-radius: 10px;
22
+ box-shadow: 0 10px 40px rgba(0,0,0,0.2);
23
+ text-align: center;
24
+ }
25
+ h2 { color: #27ae60; }
26
+ a { color: #667eea; }
27
+ </style>
28
+ </head>
29
+ <body>
30
+ <%
31
+ // 清除 session
32
+ session.invalidate();
33
+
34
+ // 减少在线计数
35
+ Integer onlineCount = (Integer) application.getAttribute("onlineCount");
36
+ if (onlineCount != null && onlineCount > 0) {
37
+ onlineCount--;
38
+ application.setAttribute("onlineCount", onlineCount);
39
+ }
40
+ %>
41
+ <div class="message">
42
+ <h2>✓ 已成功退出登录</h2>
43
+ <p>2 秒后跳转到首页...</p>
44
+ <p><a href="index.jsp">立即跳转</a></p>
45
+ </div>
46
+ </body>
47
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/WebContent/register.jsp ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ page import="com.netshop.User" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>用户注册 - NetShop</title>
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
12
+ display: flex;
13
+ justify-content: center;
14
+ align-items: center;
15
+ min-height: 100vh;
16
+ margin: 0;
17
+ padding: 20px;
18
+ }
19
+ .register-container {
20
+ background: white;
21
+ padding: 40px;
22
+ border-radius: 10px;
23
+ box-shadow: 0 10px 40px rgba(0,0,0,0.2);
24
+ width: 400px;
25
+ }
26
+ h2 {
27
+ text-align: center;
28
+ color: #333;
29
+ margin-bottom: 30px;
30
+ }
31
+ .form-group {
32
+ margin-bottom: 20px;
33
+ }
34
+ label {
35
+ display: block;
36
+ margin-bottom: 8px;
37
+ color: #555;
38
+ font-weight: bold;
39
+ }
40
+ input[type="text"],
41
+ input[type="password"],
42
+ input[type="email"] {
43
+ width: 100%;
44
+ padding: 12px;
45
+ border: 2px solid #ddd;
46
+ border-radius: 6px;
47
+ font-size: 14px;
48
+ }
49
+ input:focus {
50
+ outline: none;
51
+ border-color: #667eea;
52
+ }
53
+ input[type="submit"] {
54
+ width: 100%;
55
+ padding: 14px;
56
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
57
+ color: white;
58
+ border: none;
59
+ border-radius: 6px;
60
+ cursor: pointer;
61
+ font-size: 16px;
62
+ font-weight: bold;
63
+ }
64
+ .error {
65
+ color: #e74c3c;
66
+ background: #fde8e8;
67
+ padding: 10px;
68
+ border-radius: 4px;
69
+ margin-bottom: 20px;
70
+ }
71
+ .success {
72
+ color: #27ae60;
73
+ background: #e8f8f0;
74
+ padding: 10px;
75
+ border-radius: 4px;
76
+ margin-bottom: 20px;
77
+ }
78
+ .links {
79
+ text-align: center;
80
+ margin-top: 20px;
81
+ }
82
+ .links a {
83
+ color: #667eea;
84
+ text-decoration: none;
85
+ }
86
+ </style>
87
+ </head>
88
+ <body>
89
+ <div class="register-container">
90
+ <h2>📝 用户注册</h2>
91
+
92
+ <%
93
+ String error = (String) request.getAttribute("error");
94
+ String success = (String) request.getAttribute("success");
95
+
96
+ if (error != null) {
97
+ %>
98
+ <div class="error"><%= error %></div>
99
+ <% } else if (success != null) { %>
100
+ <div class="success"><%= success %></div>
101
+ <% } %>
102
+
103
+ <form action="register.jsp" method="post">
104
+ <div class="form-group">
105
+ <label for="username">用户名</label>
106
+ <input type="text" id="username" name="username" required placeholder="请输入用户名">
107
+ </div>
108
+ <div class="form-group">
109
+ <label for="password">密码</label>
110
+ <input type="password" id="password" name="password" required placeholder="请输入密码">
111
+ </div>
112
+ <div class="form-group">
113
+ <label for="email">邮箱</label>
114
+ <input type="email" id="email" name="email" required placeholder="请输入邮箱">
115
+ </div>
116
+ <div class="form-group">
117
+ <input type="submit" value="注 册">
118
+ </div>
119
+ </form>
120
+
121
+ <div class="links">
122
+ <p>已有账号?<a href="login.jsp">立即登录</a></p>
123
+ <p><a href="index.jsp">返回首页</a></p>
124
+ </div>
125
+ </div>
126
+
127
+ <%
128
+ if ("POST".equalsIgnoreCase(request.getMethod())) {
129
+ String username = request.getParameter("username");
130
+ String password = request.getParameter("password");
131
+ String email = request.getParameter("email");
132
+
133
+ // 验证
134
+ if (username == null || username.length() < 3) {
135
+ request.setAttribute("error", "用户名至少 3 个字符!");
136
+ } else if (password == null || password.length() < 6) {
137
+ request.setAttribute("error", "密码至少 6 个字符!");
138
+ } else if (email == null || !email.contains("@")) {
139
+ request.setAttribute("error", "请输入有效的邮箱地址!");
140
+ } else {
141
+ // 注册成功
142
+ User user = new User(username, password);
143
+ user.setEmail(email);
144
+ session.setAttribute("currentUser", user);
145
+ request.setAttribute("success", "注册成功!欢迎加入 NetShop!");
146
+ }
147
+ }
148
+ %>
149
+ </body>
150
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/src/com/netshop/Product.java ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package com.netshop;
2
+
3
+ import java.io.Serializable;
4
+
5
+ /**
6
+ * 商品 JavaBean
7
+ */
8
+ public class Product implements Serializable {
9
+
10
+ private static final long serialVersionUID = 1L;
11
+
12
+ private int id;
13
+ private String name;
14
+ private String description;
15
+ private double price;
16
+ private String category;
17
+ private int stock;
18
+
19
+ public Product() {
20
+ super();
21
+ }
22
+
23
+ public Product(int id, String name, double price) {
24
+ this.id = id;
25
+ this.name = name;
26
+ this.price = price;
27
+ }
28
+
29
+ public int getId() {
30
+ return id;
31
+ }
32
+
33
+ public void setId(int id) {
34
+ this.id = id;
35
+ }
36
+
37
+ public String getName() {
38
+ return name;
39
+ }
40
+
41
+ public void setName(String name) {
42
+ this.name = name;
43
+ }
44
+
45
+ public String getDescription() {
46
+ return description;
47
+ }
48
+
49
+ public void setDescription(String description) {
50
+ this.description = description;
51
+ }
52
+
53
+ public double getPrice() {
54
+ return price;
55
+ }
56
+
57
+ public void setPrice(double price) {
58
+ this.price = price;
59
+ }
60
+
61
+ public String getCategory() {
62
+ return category;
63
+ }
64
+
65
+ public void setCategory(String category) {
66
+ this.category = category;
67
+ }
68
+
69
+ public int getStock() {
70
+ return stock;
71
+ }
72
+
73
+ public void setStock(int stock) {
74
+ this.stock = stock;
75
+ }
76
+ }
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study2/src/com/netshop/User.java ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package com.netshop;
2
+
3
+ import java.io.Serializable;
4
+
5
+ /**
6
+ * 用户 JavaBean
7
+ */
8
+ public class User implements Serializable {
9
+
10
+ private static final long serialVersionUID = 1L;
11
+
12
+ private String username;
13
+ private String password;
14
+ private String email;
15
+ private String phone;
16
+
17
+ public User() {
18
+ super();
19
+ }
20
+
21
+ public User(String username, String password) {
22
+ this.username = username;
23
+ this.password = password;
24
+ }
25
+
26
+ public String getUsername() {
27
+ return username;
28
+ }
29
+
30
+ public void setUsername(String username) {
31
+ this.username = username;
32
+ }
33
+
34
+ public String getPassword() {
35
+ return password;
36
+ }
37
+
38
+ public void setPassword(String password) {
39
+ this.password = password;
40
+ }
41
+
42
+ public String getEmail() {
43
+ return email;
44
+ }
45
+
46
+ public void setEmail(String email) {
47
+ this.email = email;
48
+ }
49
+
50
+ public String getPhone() {
51
+ return phone;
52
+ }
53
+
54
+ public void setPhone(String phone) {
55
+ this.phone = phone;
56
+ }
57
+ }
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/README.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 实验三:Struts 2 框架应用
2
+
3
+ ## 一、实验目的
4
+ 1. 熟练掌握 Struts 2 框架的应用开发过程
5
+ 2. 熟练掌握 Struts 2 框架的处理流程
6
+ 3. 熟练掌握 Struts 2 配置文件的应用
7
+
8
+ ## 二、实验内容
9
+ 应用 Struts 2 框架,实现一个简单的学生信息录入功能:
10
+ 1. 建立基于 Struts 2 的 Web 应用 studentStruts2
11
+ 2. 完成用户登录和学生信息录入功能(页面分别为 login.jsp 和 input.jsp)
12
+ 3. login.jsp 页面实现用户登录,验证通过后进入信息录入页面
13
+
14
+ ## 三、项目结构
15
+ ```
16
+ study3/
17
+ ├── README.md
18
+ ├── src/
19
+ │ ├── com/example/
20
+ │ │ ├── LoginAction.java
21
+ │ │ └── StudentAction.java
22
+ │ └── struts.xml
23
+ └── WebContent/
24
+ ├── login.jsp
25
+ ├── input.jsp
26
+ └── WEB-INF/web.xml
27
+ ```
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/WebContent/WEB-INF/web.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="3.0">
3
+ <display-name>Struts 2 Student Example</display-name>
4
+ <welcome-file-list><welcome-file>login.jsp</welcome-file></welcome-file-list>
5
+ <filter>
6
+ <filter-name>struts2</filter-name>
7
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
8
+ </filter>
9
+ <filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping>
10
+ </web-app>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/WebContent/input.jsp ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ taglib prefix="s" uri="/struts-tags" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>学生信息录入</title>
8
+ <style>
9
+ body { font-family: Arial; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; padding: 20px; }
10
+ .container { background: white; padding: 40px; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); width: 450px; }
11
+ h2 { text-align: center; color: #333; margin-bottom: 30px; }
12
+ .form-group { margin-bottom: 20px; }
13
+ label { display: block; margin-bottom: 8px; color: #555; font-weight: bold; }
14
+ input[type="text"], select { width: 100%; padding: 12px; border: 2px solid #ddd; border-radius: 6px; font-size: 14px; }
15
+ input[type="submit"] { width: 100%; padding: 14px; background: linear-gradient(135deg, #667eea, #764ba2); color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; }
16
+ </style>
17
+ </head>
18
+ <body>
19
+ <div class="container">
20
+ <h2>📝 学生信息录入</h2>
21
+ <s:form action="student" method="post" theme="simple">
22
+ <div class="form-group">
23
+ <label>学号</label>
24
+ <s:textfield name="studentId" cssStyle="width:100%;padding:12px;border:2px solid #ddd;border-radius:6px;" placeholder="请输入学号"/>
25
+ </div>
26
+ <div class="form-group">
27
+ <label>姓名</label>
28
+ <s:textfield name="studentName" cssStyle="width:100%;padding:12px;border:2px solid #ddd;border-radius:6px;" placeholder="请输入姓名"/>
29
+ </div>
30
+ <div class="form-group">
31
+ <label>性别</label>
32
+ <s:select name="gender" list="{'男','女'}" cssStyle="width:100%;padding:12px;border:2px solid #ddd;border-radius:6px;"/>
33
+ </div>
34
+ <div class="form-group">
35
+ <label>年龄</label>
36
+ <s:textfield name="age" cssStyle="width:100%;padding:12px;border:2px solid #ddd;border-radius:6px;" placeholder="请输入年龄"/>
37
+ </div>
38
+ <div class="form-group">
39
+ <label>专业</label>
40
+ <s:textfield name="major" cssStyle="width:100%;padding:12px;border:2px solid #ddd;border-radius:6px;" placeholder="请输入专业"/>
41
+ </div>
42
+ <div class="form-group">
43
+ <s:submit value="提交" cssStyle="width:100%;padding:14px;background:linear-gradient(135deg,#667eea,#764ba2);color:white;border:none;border-radius:6px;cursor:pointer;font-size:16px;"/>
44
+ </div>
45
+ </s:form>
46
+ </div>
47
+ </body>
48
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/WebContent/login.jsp ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ taglib prefix="s" uri="/struts-tags" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>学生登录 - Struts 2</title>
8
+ <style>
9
+ body { font-family: Arial; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
10
+ .container { background: white; padding: 40px; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); width: 350px; }
11
+ h2 { text-align: center; color: #333; margin-bottom: 30px; }
12
+ .form-group { margin-bottom: 20px; }
13
+ label { display: block; margin-bottom: 8px; color: #555; font-weight: bold; }
14
+ input[type="text"], input[type="password"] { width: 100%; padding: 12px; border: 2px solid #ddd; border-radius: 6px; font-size: 14px; }
15
+ input[type="submit"] { width: 100%; padding: 14px; background: linear-gradient(135deg, #667eea, #764ba2); color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; }
16
+ .error { color: red; margin-bottom: 15px; text-align: center; }
17
+ </style>
18
+ </head>
19
+ <body>
20
+ <div class="container">
21
+ <h2>🎓 学生系统登录</h2>
22
+ <s:form action="login" method="post" theme="simple">
23
+ <div class="form-group">
24
+ <label>用户名</label>
25
+ <s:textfield name="username" cssStyle="width:100%;padding:12px;border:2px solid #ddd;border-radius:6px;" placeholder="admin"/>
26
+ <s:fielderror fieldName="username"/>
27
+ </div>
28
+ <div class="form-group">
29
+ <label>密码</label>
30
+ <s:password name="password" cssStyle="width:100%;padding:12px;border:2px solid #ddd;border-radius:6px;" placeholder="123456"/>
31
+ <s:fielderror fieldName="password"/>
32
+ </div>
33
+ <div class="form-group">
34
+ <s:submit value="登录" cssStyle="width:100%;padding:14px;background:linear-gradient(135deg,#667eea,#764ba2);color:white;border:none;border-radius:6px;cursor:pointer;font-size:16px;"/>
35
+ </div>
36
+ </s:form>
37
+ <p style="text-align:center;margin-top:20px;color:#666;font-size:12px;">测试账号:admin / 123456</p>
38
+ </div>
39
+ </body>
40
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/WebContent/success.jsp ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ taglib prefix="s" uri="/struts-tags" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>提交成功</title>
8
+ <style>
9
+ body { font-family: Arial; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
10
+ .container { background: white; padding: 40px; border-radius:10px; box-shadow:0 10px 40px rgba(0,0,0,0.2); text-align: center; }
11
+ h2 { color: #27ae60; }
12
+ .info { background: #f9f9f9; padding: 20px; border-radius: 4px; margin: 20px 0; text-align: left; }
13
+ a { display: inline-block; margin-top: 20px; padding: 10px 30px; background: linear-gradient(135deg, #667eea, #764ba2); color: white; text-decoration: none; border-radius: 4px; }
14
+ </style>
15
+ </head>
16
+ <body>
17
+ <div class="container">
18
+ <h2>✓ 提交成功</h2>
19
+ <div class="info">
20
+ <p><strong>学号:</strong><s:property value="studentId"/></p>
21
+ <p><strong>姓名:</strong><s:property value="studentName"/></p>
22
+ <p><strong>性别:</strong><s:property value="gender"/></p>
23
+ <p><strong>年龄:</strong><s:property value="age"/></p>
24
+ <p><strong>专业:</strong><s:property value="major"/></p>
25
+ </div>
26
+ <a href="login.jsp">返回登录</a>
27
+ </div>
28
+ </body>
29
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/src/com/example/LoginAction.java ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package com.example;
2
+
3
+ import com.opensymphony.xwork2.ActionSupport;
4
+
5
+ /**
6
+ * Struts 2 登录 Action
7
+ */
8
+ public class LoginAction extends ActionSupport {
9
+
10
+ private String username;
11
+ private String password;
12
+
13
+ public String execute() throws Exception {
14
+ if ("admin".equals(username) && "123456".equals(password)) {
15
+ return SUCCESS;
16
+ } else {
17
+ addFieldError("username", "用户名或密码错误");
18
+ return INPUT;
19
+ }
20
+ }
21
+
22
+ public String getUsername() { return username; }
23
+ public void setUsername(String username) { this.username = username; }
24
+ public String getPassword() { return password; }
25
+ public void setPassword(String password) { this.password = password; }
26
+ }
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/src/com/example/StudentAction.java ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package com.example;
2
+
3
+ import com.opensymphony.xwork2.ActionSupport;
4
+
5
+ /**
6
+ * 学生信息 Action
7
+ */
8
+ public class StudentAction extends ActionSupport {
9
+
10
+ private String studentId;
11
+ private String studentName;
12
+ private String gender;
13
+ private String age;
14
+ private String major;
15
+
16
+ public String execute() throws Exception {
17
+ return SUCCESS;
18
+ }
19
+
20
+ public String input() throws Exception {
21
+ return INPUT;
22
+ }
23
+
24
+ // Getters and Setters
25
+ public String getStudentId() { return studentId; }
26
+ public void setStudentId(String studentId) { this.studentId = studentId; }
27
+ public String getStudentName() { return studentName; }
28
+ public void setStudentName(String studentName) { this.studentName = studentName; }
29
+ public String getGender() { return gender; }
30
+ public void setGender(String gender) { this.gender = gender; }
31
+ public String getAge() { return age; }
32
+ public void setAge(String age) { this.age = age; }
33
+ public String getMajor() { return major; }
34
+ public void setMajor(String major) { this.major = major; }
35
+ }
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study3/src/struts.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE struts PUBLIC
3
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
4
+ "http://struts.apache.org/dtds/struts-2.0.dtd">
5
+
6
+ <struts>
7
+ <package name="default" namespace="/" extends="struts-default">
8
+
9
+ <action name="login" class="com.example.LoginAction">
10
+ <result name="success">/input.jsp</result>
11
+ <result name="input">/login.jsp</result>
12
+ </action>
13
+
14
+ <action name="student" class="com.example.StudentAction">
15
+ <result name="success">/success.jsp</result>
16
+ <result name="input">/input.jsp</result>
17
+ </action>
18
+
19
+ </package>
20
+ </struts>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study4/README.md ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 实验四:Struts 2 输入校验
2
+
3
+ ## 一、实验目的
4
+ 1. 理解 Struts 2 的输入校验机制
5
+ 2. 熟练掌握 Struts 2 校验框架的使用
6
+
7
+ ## 二、实验内容
8
+ 完成一个用户注册程序,用户信息包括用户名、密码、再次输入密码、出生日期、身高、电话、电子邮箱、博客、地址等。
9
+
10
+ ### 校验规则:
11
+ 1. 用户名不能为空
12
+ 2. 用户名长度必须在 4~20 位之间且由字母、数字和下划线组成
13
+ 3. 密码不能为空,长度至少 6 位
14
+ 4. 两次密码输入必须一致
15
+ 5. 出生日期必须在 1900-01-01 到 2013-12-31 之间
16
+ 6. 身高必须在 1.0 到 2.5 米之间
17
+ 7. 电话格式验证
18
+
19
+ ## 三、项目结构
20
+ ```
21
+ study4/
22
+ ├── README.md
23
+ ├── src/
24
+ │ ├── com/example/
25
+ │ │ ├── RegisterAction.java
26
+ │ │ └── RegisterAction-validation.xml
27
+ │ └── struts.xml
28
+ └── WebContent/
29
+ ├── register.jsp
30
+ └── WEB-INF/web.xml
31
+ ```
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study4/WebContent/WEB-INF/web.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="3.0">
3
+ <display-name>Struts 2 Register Example</display-name>
4
+ <welcome-file-list><welcome-file>register.jsp</welcome-file></welcome-file-list>
5
+ <filter>
6
+ <filter-name>struts2</filter-name>
7
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
8
+ </filter>
9
+ <filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping>
10
+ </web-app>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study4/WebContent/register.jsp ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ taglib prefix="s" uri="/struts-tags" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>用户注册 - Struts 2 校验</title>
8
+ <style>
9
+ body { font-family: Arial; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; padding: 20px; }
10
+ .container { background: white; padding: 40px; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); width: 500px; max-height: 90vh; overflow-y: auto; }
11
+ h2 { text-align: center; color: #333; margin-bottom: 30px; }
12
+ .form-group { margin-bottom: 15px; }
13
+ label { display: block; margin-bottom: 5px; color: #555; font-weight: bold; font-size: 14px; }
14
+ input[type="text"], input[type="password"], input[type="email"], input[type="date"] { width: 100%; padding: 10px; border: 2px solid #ddd; border-radius: 6px; font-size: 14px; }
15
+ input[type="submit"] { width: 100%; padding: 14px; background: linear-gradient(135deg, #667eea, #764ba2); color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; margin-top: 10px; }
16
+ .error { color: #e74c3c; font-size: 12px; margin-top: 5px; }
17
+ .hint { color: #999; font-size: 12px; margin-top: 3px; }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <div class="container">
22
+ <h2>📝 用户注册</h2>
23
+ <s:form action="register" method="post" theme="simple">
24
+ <div class="form-group">
25
+ <label>用户名 *</label>
26
+ <s:textfield name="username" cssStyle="width:100%;padding:10px;border:2px solid #ddd;border-radius:6px;"/>
27
+ <s:fielderror fieldName="username" cssClass="error"/>
28
+ <div class="hint">4-20 位字母、数字或下划线</div>
29
+ </div>
30
+ <div class="form-group">
31
+ <label>密码 *</label>
32
+ <s:password name="password" cssStyle="width:100%;padding:10px;border:2px solid #ddd;border-radius:6px;"/>
33
+ <s:fielderror fieldName="password" cssClass="error"/>
34
+ <div class="hint">至少 6 位</div>
35
+ </div>
36
+ <div class="form-group">
37
+ <label>确认密码 *</label>
38
+ <s:password name="confirmPassword" cssStyle="width:100%;padding:10px;border:2px solid #ddd;border-radius:6px;"/>
39
+ <s:fielderror fieldName="confirmPassword" cssClass="error"/>
40
+ </div>
41
+ <div class="form-group">
42
+ <label>出生日期</label>
43
+ <s:textfield name="birthDate" cssStyle="width:100%;padding:10px;border:2px solid #ddd;border-radius:6px;" placeholder="YYYY-MM-DD"/>
44
+ <div class="hint">1900-01-01 至 2013-12-31</div>
45
+ </div>
46
+ <div class="form-group">
47
+ <label>身高 (米)</label>
48
+ <s:textfield name="height" cssStyle="width:100%;padding:10px;border:2px solid #ddd;border-radius:6px;" placeholder="1.75"/>
49
+ <div class="hint">1.0 - 2.5 米</div>
50
+ </div>
51
+ <div class="form-group">
52
+ <label>电话</label>
53
+ <s:textfield name="phone" cssStyle="width:100%;padding:10px;border:2px solid #ddd;border-radius:6px;" placeholder="13800138000"/>
54
+ <s:fielderror fieldName="phone" cssClass="error"/>
55
+ </div>
56
+ <div class="form-group">
57
+ <label>邮箱</label>
58
+ <s:textfield name="email" cssStyle="width:100%;padding:10px;border:2px solid #ddd;border-radius:6px;"/>
59
+ <s:fielderror fieldName="email" cssClass="error"/>
60
+ </div>
61
+ <div class="form-group">
62
+ <label>博客地址</label>
63
+ <s:textfield name="blog" cssStyle="width:100%;padding:10px;border:2px solid #ddd;border-radius:6px;"/>
64
+ </div>
65
+ <div class="form-group">
66
+ <label>地址</label>
67
+ <s:textfield name="address" cssStyle="width:100%;padding:10px;border:2px solid #ddd;border-radius:6px;"/>
68
+ </div>
69
+ <div class="form-group">
70
+ <s:submit value="注 册" cssStyle="width:100%;padding:14px;background:linear-gradient(135deg,#667eea,#764ba2);color:white;border:none;border-radius:6px;cursor:pointer;font-size:16px;"/>
71
+ </div>
72
+ </s:form>
73
+ </div>
74
+ </body>
75
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study4/WebContent/success.jsp ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ taglib prefix="s" uri="/struts-tags" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>注册成功</title>
8
+ <style>
9
+ body { font-family: Arial; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
10
+ .container { background: white; padding: 40px; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); text-align: center; max-width: 500px; }
11
+ h2 { color: #27ae60; }
12
+ .info { background: #f9f9f9; padding: 20px; border-radius: 4px; margin: 20px 0; text-align: left; }
13
+ a { display: inline-block; margin-top: 20px; padding: 10px 30px; background: linear-gradient(135deg, #667eea, #764ba2); color: white; text-decoration: none; border-radius: 4px; }
14
+ </style>
15
+ </head>
16
+ <body>
17
+ <div class="container">
18
+ <h2>✓ 注册成功</h2>
19
+ <div class="info">
20
+ <p><strong>用户名:</strong><s:property value="username"/></p>
21
+ <p><strong>邮箱:</strong><s:property value="email"/></p>
22
+ <p><strong>电话:</strong><s:property value="phone"/></p>
23
+ <p><strong>身高:</strong><s:property value="height"/> 米</p>
24
+ </div>
25
+ <a href="register.jsp">返回注册</a>
26
+ </div>
27
+ </body>
28
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study4/src/com/example/RegisterAction.java ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package com.example;
2
+
3
+ import com.opensymphony.xwork2.ActionSupport;
4
+ import java.text.*;
5
+ import java.util.regex.*;
6
+
7
+ /**
8
+ * 用户注册 Action - 包含输入校验
9
+ */
10
+ public class RegisterAction extends ActionSupport {
11
+
12
+ private String username;
13
+ private String password;
14
+ private String confirmPassword;
15
+ private String birthDate;
16
+ private String height;
17
+ private String phone;
18
+ private String email;
19
+ private String blog;
20
+ private String address;
21
+
22
+ // 自定义校验方法
23
+ public void validate() {
24
+ // 用户名校验:4-20 位,字母数字下划线
25
+ if (username == null || username.trim().isEmpty()) {
26
+ addFieldError("username", "用户名不能为空");
27
+ } else if (!username.matches("^[a-zA-Z0-9_]{4,20}$")) {
28
+ addFieldError("username", "用户名必须是 4-20 位的字母、数字或下划线");
29
+ }
30
+
31
+ // 密码校验
32
+ if (password == null || password.length() < 6) {
33
+ addFieldError("password", "密码长度至少 6 位");
34
+ }
35
+
36
+ // 确认密码校验
37
+ if (!password.equals(confirmPassword)) {
38
+ addFieldError("confirmPassword", "两次密码输入不一致");
39
+ }
40
+
41
+ // 出生日期校验:必须在 1900-01-01 到 2013-12-31 之间
42
+ if (birthDate != null && !birthDate.trim().isEmpty()) {
43
+ try {
44
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
45
+ sdf.setLenient(false);
46
+ java.util.Date date = sdf.parse(birthDate);
47
+ java.util.Date minDate = sdf.parse("1900-01-01");
48
+ java.util.Date maxDate = sdf.parse("2013-12-31");
49
+ if (date.before(minDate) || date.after(maxDate)) {
50
+ addFieldError("birthDate", "出生日期必须在 1900-01-01 到 2013-12-31 之间");
51
+ }
52
+ } catch (ParseException e) {
53
+ addFieldError("birthDate", "请输入有效的日期格式(yyyy-MM-dd)");
54
+ }
55
+ }
56
+
57
+ // 身高校验:必须在 1.0 到 2.0 米之间
58
+ if (height != null && !height.trim().isEmpty()) {
59
+ try {
60
+ double h = Double.parseDouble(height);
61
+ if (h < 1.0 || h > 2.0) {
62
+ addFieldError("height", "身高必须在 1.0 到 2.0 米之间");
63
+ }
64
+ } catch (NumberFormatException e) {
65
+ addFieldError("height", "请输入有效的身高数值");
66
+ }
67
+ }
68
+
69
+ // 博客地址校验
70
+ if (blog != null && !blog.trim().isEmpty() && !blog.matches("^(https?://).+$")) {
71
+ addFieldError("blog", "请输入有效的博客地址(以 http:// 或 https:// 开头)");
72
+ }
73
+
74
+ // 电话校验
75
+ if (phone != null && !phone.matches("^1[3-9]\\d{9}$") && !phone.matches("^0\\d{2,3}-\\d{7,8}$")) {
76
+ addFieldError("phone", "请输入有效的电话号码");
77
+ }
78
+
79
+ // 邮箱校验
80
+ if (email != null && !email.matches("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$")) {
81
+ addFieldError("email", "请输入有效的邮箱地址");
82
+ }
83
+ }
84
+
85
+ public String execute() throws Exception {
86
+ return SUCCESS;
87
+ }
88
+
89
+ // Getters and Setters
90
+ public String getUsername() { return username; }
91
+ public void setUsername(String username) { this.username = username; }
92
+ public String getPassword() { return password; }
93
+ public void setPassword(String password) { this.password = password; }
94
+ public String getConfirmPassword() { return confirmPassword; }
95
+ public void setConfirmPassword(String confirmPassword) { this.confirmPassword = confirmPassword; }
96
+ public String getBirthDate() { return birthDate; }
97
+ public void setBirthDate(String birthDate) { this.birthDate = birthDate; }
98
+ public String getHeight() { return height; }
99
+ public void setHeight(String height) { this.height = height; }
100
+ public String getPhone() { return phone; }
101
+ public void setPhone(String phone) { this.phone = phone; }
102
+ public String getEmail() { return email; }
103
+ public void setEmail(String email) { this.email = email; }
104
+ public String getBlog() { return blog; }
105
+ public void setBlog(String blog) { this.blog = blog; }
106
+ public String getAddress() { return address; }
107
+ public void setAddress(String address) { this.address = address; }
108
+ }
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study4/src/struts.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
3
+ <struts>
4
+ <package name="default" namespace="/" extends="struts-default">
5
+ <action name="register" class="com.example.RegisterAction">
6
+ <result name="success">/success.jsp</result>
7
+ <result name="input">/register.jsp</result>
8
+ </action>
9
+ </package>
10
+ </struts>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study5/README.md ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 实验五:Struts 2 标签库应用
2
+
3
+ ## 一、实验目的
4
+ 熟练掌握 Struts 2 标签库的使用
5
+
6
+ ## 二、实验内容
7
+ 应用 Struts 2 框架,实现一个简单的商品分类搜索功能:
8
+ 1. 建立基于 Struts 2 的 Web 应用 struts2shop
9
+ 2. 完成商品的分类搜索和商品信息显示功能(search.jsp 和 display.jsp)
10
+ 3. 使用表单标签、控制标签等实现
11
+
12
+ ## 三、项目结构
13
+ ```
14
+ study5/
15
+ ├── README.md
16
+ ├── src/
17
+ │ ├── com/example/
18
+ │ │ └── SearchAction.java
19
+ │ └── struts.xml
20
+ └── WebContent/
21
+ ├── search.jsp
22
+ ├── display.jsp
23
+ └── WEB-INF/web.xml
24
+ ```
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study5/WebContent/WEB-INF/web.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="3.0">
3
+ <display-name>Struts 2 Shop Example</display-name>
4
+ <welcome-file-list><welcome-file>search.jsp</welcome-file></welcome-file-list>
5
+ <filter>
6
+ <filter-name>struts2</filter-name>
7
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
8
+ </filter>
9
+ <filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping>
10
+ </web-app>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study5/WebContent/display.jsp ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ taglib prefix="s" uri="/struts-tags" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>搜索结果</title>
8
+ <style>
9
+ body { font-family: Arial; background: linear-gradient(135deg, #667eea, #764ba2); padding: 40px 20px; min-height: 100vh; margin: 0; }
10
+ .container { max-width: 800px; margin: 0 auto; background: white; padding: 40px; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); }
11
+ h2 { text-align: center; color: #333; margin-bottom: 30px; }
12
+ .product-list { list-style: none; padding: 0; }
13
+ .product-item { display: flex; justify-content: space-between; padding: 15px; border-bottom: 1px solid #eee; }
14
+ .product-item:last-child { border-bottom: none; }
15
+ .product-name { font-weight: bold; color: #333; }
16
+ .product-price { color: #e74c3c; font-weight: bold; }
17
+ .product-category { color: #667eea; font-size: 13px; }
18
+ a { display: inline-block; margin-top: 20px; padding: 10px 30px; background: linear-gradient(135deg, #667eea, #764ba2); color: white; text-decoration: none; border-radius: 4px; }
19
+ .empty { text-align: center; color: #999; padding: 40px; }
20
+ </style>
21
+ </head>
22
+ <body>
23
+ <div class="container">
24
+ <h2>📦 搜索结果</h2>
25
+ <s:if test="products.size() > 0">
26
+ <ul class="product-list">
27
+ <s:iterator value="products">
28
+ <li class="product-item">
29
+ <div>
30
+ <div class="product-name"><s:property value="name"/></div>
31
+ <div class="product-category"><s:property value="category"/></div>
32
+ </div>
33
+ <div class="product-price">¥<s:property value="price"/></div>
34
+ </li>
35
+ </s:iterator>
36
+ </ul>
37
+ </s:if>
38
+ <s:else>
39
+ <div class="empty">暂无商品</div>
40
+ </s:else>
41
+ <div style="text-align:center;">
42
+ <a href="search.jsp">返回搜索</a>
43
+ </div>
44
+ </div>
45
+ </body>
46
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study5/WebContent/search.jsp ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ taglib prefix="s" uri="/struts-tags" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>商品搜索 - Struts 2 标签库</title>
8
+ <style>
9
+ body { font-family: Arial; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; padding: 20px; }
10
+ .container { background: white; padding: 40px; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); width: 450px; }
11
+ h2 { text-align: center; color: #333; margin-bottom: 30px; }
12
+ .form-group { margin-bottom: 20px; }
13
+ label { display: block; margin-bottom: 8px; color: #555; font-weight: bold; }
14
+ select { width: 100%; padding: 12px; border: 2px solid #ddd; border-radius: 6px; font-size: 14px; }
15
+ input[type="submit"] { width: 100%; padding: 14px; background: linear-gradient(135deg, #667eea, #764ba2); color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; }
16
+ </style>
17
+ </head>
18
+ <body>
19
+ <div class="container">
20
+ <h2>🔍 商品搜索</h2>
21
+ <s:form action="search" method="post" theme="simple">
22
+ <div class="form-group">
23
+ <label>选择商品分类</label>
24
+ <s:select name="category" list="{'全部','手机','电脑','平板','耳机','手表'}"
25
+ cssStyle="width:100%;padding:12px;border:2px solid #ddd;border-radius:6px;"/>
26
+ </div>
27
+ <div class="form-group">
28
+ <s:submit value="搜 索" cssStyle="width:100%;padding:14px;background:linear-gradient(135deg,#667eea,#764ba2);color:white;border:none;border-radius:6px;cursor:pointer;font-size:16px;"/>
29
+ </div>
30
+ </s:form>
31
+ </div>
32
+ </body>
33
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study5/src/com/example/SearchAction.java ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package com.example;
2
+
3
+ import com.opensymphony.xwork2.ActionSupport;
4
+ import java.util.*;
5
+
6
+ /**
7
+ * 商品搜索 Action
8
+ */
9
+ public class SearchAction extends ActionSupport {
10
+
11
+ private String category;
12
+ private List<Map<String, Object>> products;
13
+
14
+ // 商品分类
15
+ public static final String[] CATEGORIES = {"手机", "电脑", "平板", "耳机", "手表"};
16
+
17
+ public String execute() throws Exception {
18
+ products = new ArrayList<>();
19
+
20
+ // 模拟商品数据
21
+ Map<String, Object> p1 = new HashMap<>();
22
+ p1.put("name", "iPhone 15");
23
+ p1.put("price", 7999.0);
24
+ p1.put("category", "手机");
25
+ products.add(p1);
26
+
27
+ Map<String, Object> p2 = new HashMap<>();
28
+ p2.put("name", "MacBook Pro");
29
+ p2.put("price", 14999.0);
30
+ p2.put("category", "电脑");
31
+ products.add(p2);
32
+
33
+ Map<String, Object> p3 = new HashMap<>();
34
+ p3.put("name", "iPad Air");
35
+ p3.put("price", 4799.0);
36
+ p3.put("category", "平板");
37
+ products.add(p3);
38
+
39
+ // 如果选择了分类,进行过滤
40
+ if (category != null && !category.isEmpty() && !"全部".equals(category)) {
41
+ List<Map<String, Object>> filtered = new ArrayList<>();
42
+ for (Map<String, Object> p : products) {
43
+ if (category.equals(p.get("category"))) {
44
+ filtered.add(p);
45
+ }
46
+ }
47
+ products = filtered;
48
+ }
49
+
50
+ return SUCCESS;
51
+ }
52
+
53
+ public String getCategory() { return category; }
54
+ public void setCategory(String category) { this.category = category; }
55
+ public List<Map<String, Object>> getProducts() { return products; }
56
+ public void setProducts(List<Map<String, Object>> products) { this.products = products; }
57
+ public String[] getCategories() { return CATEGORIES; }
58
+ }
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study5/src/struts.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
3
+ <struts>
4
+ <package name="default" namespace="/" extends="struts-default">
5
+ <action name="search" class="com.example.SearchAction">
6
+ <result name="success">/display.jsp</result>
7
+ <result name="input">/search.jsp</result>
8
+ </action>
9
+ </package>
10
+ </struts>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/README.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 实验六:数据库应用
2
+
3
+ ## 一、实验目的
4
+ 1. 掌握 Java 访问数据库的基本步骤
5
+ 2. 掌握 JDBC 连接数据库的基本方法
6
+ 3. 掌握 JDBC-ODBC 桥连接数据库的基本方法
7
+
8
+ ## 二、实验内容
9
+ 实现一个简单的网上商店,以 SQL Server 或 Access 数据库为例:
10
+ 1. 首页(index.jsp)中实现商品信息的浏览或搜索功能
11
+ 2. 实现商品信息的录入功能(newgoods.jsp)
12
+ 3. 实现商品信息的修改和删除功能
13
+
14
+ ## 三、数据库设计
15
+ ```sql
16
+ CREATE TABLE products (
17
+ id INT PRIMARY KEY IDENTITY(1,1),
18
+ name NVARCHAR(100),
19
+ price DECIMAL(10,2),
20
+ description NVARCHAR(500),
21
+ category NVARCHAR(50),
22
+ stock INT
23
+ );
24
+ ```
25
+
26
+ ## 四、项目结构
27
+ ```
28
+ study6/
29
+ ├── README.md
30
+ ├── src/
31
+ │ ├── com/example/
32
+ │ │ ├── DBUtil.java
33
+ │ │ └── ProductDAO.java
34
+ │ └── struts.xml
35
+ └── WebContent/
36
+ ├── index.jsp
37
+ ├── newgoods.jsp
38
+ ├── edit.jsp
39
+ └── WEB-INF/web.xml
40
+ ```
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/WebContent/WEB-INF/web.xml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="3.0">
3
+ <display-name>JDBC Database Example</display-name>
4
+ <welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list>
5
+ </web-app>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/WebContent/add.jsp ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ page import="com.example.*" %>
3
+ <%
4
+ request.setCharacterEncoding("UTF-8");
5
+ String name = request.getParameter("name");
6
+ double price = Double.parseDouble(request.getParameter("price"));
7
+ String category = request.getParameter("category");
8
+ int stock = Integer.parseInt(request.getParameter("stock"));
9
+ String desc = request.getParameter("description");
10
+
11
+ ProductDAO dao = new ProductDAO();
12
+ dao.addProduct(name, price, desc, category, stock);
13
+ response.sendRedirect("index.jsp");
14
+ %>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/WebContent/delete.jsp ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ page import="com.example.*" %>
3
+ <%
4
+ int id = Integer.parseInt(request.getParameter("id"));
5
+ ProductDAO dao = new ProductDAO();
6
+ dao.deleteProduct(id);
7
+ response.sendRedirect("index.jsp");
8
+ %>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/WebContent/edit.jsp ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ page import="java.util.*, com.example.*" %>
3
+ <%
4
+ int id = Integer.parseInt(request.getParameter("id"));
5
+ ProductDAO dao = new ProductDAO();
6
+ Map<String, Object> product = dao.getProductById(id);
7
+ %>
8
+ <!DOCTYPE html>
9
+ <html>
10
+ <head>
11
+ <meta charset="UTF-8">
12
+ <title>编辑商品</title>
13
+ <style>
14
+ body { font-family: Arial; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; }
15
+ .container { background: white; padding: 40px; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); width: 450px; }
16
+ h2 { text-align: center; color: #333; margin-bottom: 30px; }
17
+ .form-group { margin-bottom: 15px; }
18
+ label { display: block; margin-bottom: 5px; color: #555; font-weight: bold; }
19
+ input, select, textarea { width: 100%; padding: 10px; border: 2px solid #ddd; border-radius: 6px; }
20
+ input[type="submit"] { background: linear-gradient(135deg, #667eea, #764ba2); color: white; border: none; cursor: pointer; }
21
+ a { display: block; text-align: center; margin-top: 15px; color: #667eea; }
22
+ </style>
23
+ </head>
24
+ <body>
25
+ <div class="container">
26
+ <h2>✏️ 编辑商品</h2>
27
+ <form action="update.jsp" method="post">
28
+ <input type="hidden" name="id" value="<%= id %>">
29
+ <div class="form-group">
30
+ <label>商品名称</label>
31
+ <input type="text" name="name" value="<%= product.get("name") %>">
32
+ </div>
33
+ <div class="form-group">
34
+ <label>价格</label>
35
+ <input type="number" step="0.01" name="price" value="<%= product.get("price") %>">
36
+ </div>
37
+ <div class="form-group">
38
+ <label>分类</label>
39
+ <select name="category">
40
+ <option <%= "手机".equals(product.get("category")) ? "selected" : "" %>>手机</option>
41
+ <option <%= "电脑".equals(product.get("category")) ? "selected" : "" %>>电脑</option>
42
+ <option <%= "平板".equals(product.get("category")) ? "selected" : "" %>>平板</option>
43
+ <option <%= "耳机".equals(product.get("category")) ? "selected" : "" %>>耳机</option>
44
+ <option <%= "手表".equals(product.get("category")) ? "selected" : "" %>>手表</option>
45
+ </select>
46
+ </div>
47
+ <div class="form-group">
48
+ <label>库存</label>
49
+ <input type="number" name="stock" value="<%= product.get("stock") %>">
50
+ </div>
51
+ <div class="form-group">
52
+ <label>描述</label>
53
+ <textarea name="description" rows="3"><%= product.get("description") %></textarea>
54
+ </div>
55
+ <input type="submit" value="保存修改">
56
+ </form>
57
+ <a href="index.jsp">返回列表</a>
58
+ </div>
59
+ </body>
60
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/WebContent/index.jsp ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <%@ page import="java.util.*, com.example.*" %>
3
+ <!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <title>网上商店 - 数据库应用</title>
8
+ <style>
9
+ body { font-family: Arial; background: #f5f5f5; margin: 0; padding: 20px; }
10
+ .container { max-width: 900px; margin: 0 auto; background: white; padding: 30px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
11
+ h1 { text-align: center; color: #333; }
12
+ .toolbar { text-align: center; margin-bottom: 20px; }
13
+ .btn { padding: 10px 20px; background: #667eea; color: white; text-decoration: none; border-radius: 5px; display: inline-block; }
14
+ table { width: 100%; border-collapse: collapse; margin-top: 20px; }
15
+ th, td { padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }
16
+ th { background: #667eea; color: white; }
17
+ tr:hover { background: #f5f5f5; }
18
+ .actions a { margin-right: 10px; color: #667eea; }
19
+ .delete { color: #e74c3c !important; }
20
+ .error { color: red; text-align: center; padding: 20px; }
21
+ </style>
22
+ </head>
23
+ <body>
24
+ <div class="container">
25
+ <h1>🛒 网上商店 - 商品管理</h1>
26
+ <div class="toolbar">
27
+ <a href="newgoods.jsp" class="btn">➕ 添加商品</a>
28
+ <a href="index.jsp" class="btn">🔄 刷新</a>
29
+ </div>
30
+
31
+ <%
32
+ try {
33
+ ProductDAO dao = new ProductDAO();
34
+ List<Map<String, Object>> products = dao.getAllProducts();
35
+
36
+ if (products.isEmpty()) {
37
+ %>
38
+ <div class="error">暂无商品,请添加!</div>
39
+ <%
40
+ } else {
41
+ %>
42
+ <table>
43
+ <thead>
44
+ <tr>
45
+ <th>ID</th>
46
+ <th>名称</th>
47
+ <th>价格</th>
48
+ <th>分类</th>
49
+ <th>库存</th>
50
+ <th>操作</th>
51
+ </tr>
52
+ </thead>
53
+ <tbody>
54
+ <% for (Map<String, Object> p : products) { %>
55
+ <tr>
56
+ <td><%= p.get("id") %></td>
57
+ <td><%= p.get("name") %></td>
58
+ <td>¥<%= p.get("price") %></td>
59
+ <td><%= p.get("category") %></td>
60
+ <td><%= p.get("stock") %></td>
61
+ <td class="actions">
62
+ <a href="edit.jsp?id=<%= p.get("id") %>">编辑</a>
63
+ <a href="delete.jsp?id=<%= p.get("id") %>" class="delete" onclick="return confirm('确定删除?')">删除</a>
64
+ </td>
65
+ </tr>
66
+ <% } %>
67
+ </tbody>
68
+ </table>
69
+ <% } %>
70
+ <% } catch (Exception e) { %>
71
+ <div class="error">数据库错误:<%= e.getMessage() %><br/>请确保数据库已配置并运行</div>
72
+ <% } %>
73
+ </div>
74
+ </body>
75
+ </html>
JavaEEweb程序设计实验2026-王非老师-范纯毓/【交付汇总】/【交付汇总】/1.全部实验代码/study6/WebContent/newgoods.jsp ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
+ <!DOCTYPE html>
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <title>添加商品</title>
7
+ <style>
8
+ body { font-family: Arial; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; }
9
+ .container { background: white; padding: 40px; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); width: 450px; }
10
+ h2 { text-align: center; color: #333; margin-bottom: 30px; }
11
+ .form-group { margin-bottom: 15px; }
12
+ label { display: block; margin-bottom: 5px; color: #555; font-weight: bold; }
13
+ input, select, textarea { width: 100%; padding: 10px; border: 2px solid #ddd; border-radius: 6px; font-size: 14px; }
14
+ input[type="submit"] { background: linear-gradient(135deg, #667eea, #764ba2); color: white; border: none; cursor: pointer; font-size: 16px; }
15
+ a { display: block; text-align: center; margin-top: 15px; color: #667eea; }
16
+ </style>
17
+ </head>
18
+ <body>
19
+ <div class="container">
20
+ <h2>➕ 添加商品</h2>
21
+ <form action="add.jsp" method="post">
22
+ <div class="form-group">
23
+ <label>商品名称</label>
24
+ <input type="text" name="name" required>
25
+ </div>
26
+ <div class="form-group">
27
+ <label>价格</label>
28
+ <input type="number" step="0.01" name="price" required>
29
+ </div>
30
+ <div class="form-group">
31
+ <label>分类</label>
32
+ <select name="category">
33
+ <option>手机</option>
34
+ <option>电脑</option>
35
+ <option>平板</option>
36
+ <option>耳机</option>
37
+ <option>手表</option>
38
+ </select>
39
+ </div>
40
+ <div class="form-group">
41
+ <label>库存</label>
42
+ <input type="number" name="stock" value="100">
43
+ </div>
44
+ <div class="form-group">
45
+ <label>描述</label>
46
+ <textarea name="description" rows="3"></textarea>
47
+ </div>
48
+ <input type="submit" value="添加商品">
49
+ </form>
50
+ <a href="index.jsp">返回列表</a>
51
+ </div>
52
+ </body>
53
+ </html>