From f16401b91375c82e96596b21e847143b9f59ec1b Mon Sep 17 00:00:00 2001 From: likingcode Date: Tue, 10 Mar 2026 00:20:58 +0800 Subject: [PATCH] feat(content): enrich structs pages with learning map and deeper CRUD guidance --- src/main/webapp/hello.jsp | 40 ++++++++++++++++ src/main/webapp/index.jsp | 76 ++++++++++++++++++++++++++++++ src/main/webapp/learn.jsp | 88 ++++++++++++++++------------------- src/main/webapp/user-form.jsp | 82 ++++++++++++++++++++++++++++++++ src/main/webapp/user-list.jsp | 80 +++++++++++++++++++++++++++++++ 5 files changed, 319 insertions(+), 47 deletions(-) create mode 100644 src/main/webapp/hello.jsp create mode 100644 src/main/webapp/index.jsp create mode 100644 src/main/webapp/user-form.jsp create mode 100644 src/main/webapp/user-list.jsp diff --git a/src/main/webapp/hello.jsp b/src/main/webapp/hello.jsp new file mode 100644 index 0000000..f198665 --- /dev/null +++ b/src/main/webapp/hello.jsp @@ -0,0 +1,40 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + Hello 示例 - Struts2 + + + +
+

👋 Hello 示例

+

${message}

+

这是 Struts2 最基础的一条链路:浏览器请求 /hello → Struts2 匹配 Action → Action 返回结果名 → JSP 被渲染。

+
+ +
+ 学习观察点 + +
+ +
+

🔍 为什么这个例子重要

+

很多人一开始学 Struts2,会直接被拦截器、标签库、OGNL、配置文件吓到。Hello 示例的价值在于:先把“请求如何进来、结果如何出去”这条最小主线跑通,再去理解更复杂的机制。

+
+ +

← 返回学习中心

+ + diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp new file mode 100644 index 0000000..062e155 --- /dev/null +++ b/src/main/webapp/index.jsp @@ -0,0 +1,76 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + Struts2 Learning Scaffold + + + +
+

🚀 Struts2 Learning Scaffold

+

不是单纯的 Struts2 演示页,而是一套带任务卡、表单实验、拦截器观察和 CRUD 流程的学习脚手架。

+ 进入学习中心 +
+ +
+ 推荐学习顺序 + +
+ +
+
+

👋 Hello 示例

+

最小 Action 示例,适合理解 Struts2 如何把请求映射到 Action,再把数据渲染到 JSP。

+ 打开示例 +
+
+

🔢 计算器实验

+

学习参数绑定、validate() 校验、字段错误回显,以及成功/失败两条分支。

+ 开始实验 +
+
+

🛡️ 拦截器观察

+

重点模块。能看到日志、执行时间、限流、监控等拦截器如何织入请求链路。

+ 观察拦截器 +
+
+

👥 用户 CRUD

+

从列表页到表单页,再到新增/编辑/删除,形成完整的 Struts2 业务流学习闭环。

+ 进入 CRUD +
+
+ +
+

📚 你会学到什么

+ +
+ + diff --git a/src/main/webapp/learn.jsp b/src/main/webapp/learn.jsp index 5c3746a..c30d4ff 100644 --- a/src/main/webapp/learn.jsp +++ b/src/main/webapp/learn.jsp @@ -5,22 +5,22 @@ Struts2 学习中心 @@ -30,7 +30,7 @@ 🧪 学习任务卡
@@ -39,33 +39,31 @@ 直接去用户管理实验
- -
-

🛡️ 拦截器 (核心特性)

-

拦截器是 Struts2 最强大的特性之一,基于责任链模式实现 AOP。

-
- 拦截器演示 + +
+
+

👋 最小闭环

+

/hello 开始,看 Action 如何返回 JSP 页面。

+ 打开 Hello
- -
- -
-

📝 基础示例

-
- Hello World - 计算器 - 用户管理 +
+

🔢 表单与校验

+

用计算器理解参数绑定、校验失败回显、成功结果显示。

+ 打开计算器 +
+
+

🛡️ 拦截器机制

+

学习 Struts2 最核心的增强机制:日志、计时、限流、监控。

+ 打开拦截器实验 +
+
+

👥 CRUD 业务流

+

通过用户管理体验列表页、表单页、重定向和状态更新。

+ 打开用户管理
- +

📚 学习路径

-

1. MVC 架构

    @@ -74,7 +72,7 @@
  • Controller: StrutsPrepareAndExecuteFilter
- +

2. 拦截器机制

    @@ -83,30 +81,26 @@
  • 执行顺序: 责任链模式(先入后出)
- +
-

3. OGNL 表达式

+

3. OGNL 与标签库

  • <s:property value="name"/> - 输出属性
  • <s:iterator value="list"> - 遍历集合
  • -
  • #request.key - 访问 request
  • +
  • <s:form> + <s:textfield> - 表单绑定
- +
-

4. 项目结构

-
-├── src/main/java/com/example/struts2/
-│   ├── action/          # Action 类
-│   └── interceptor/     # 自定义拦截器
-├── src/main/resources/
-│   └── struts.xml       # 核心配置
-└── src/main/webapp/
-    ├── WEB-INF/web.xml  # Servlet 配置
-    └── *.jsp            # 视图页面
-        
+

4. 你当前项目里有哪些实验

+
    +
  • Hello:最小 Action/JSP 映射
  • +
  • Calculator:参数绑定 + 校验 + 错误回显
  • +
  • Interceptor:理解自定义拦截器与请求链
  • +
  • User CRUD:模拟真实业务增删改查
  • +
- +

← 返回首页

- \ No newline at end of file + diff --git a/src/main/webapp/user-form.jsp b/src/main/webapp/user-form.jsp new file mode 100644 index 0000000..717a85d --- /dev/null +++ b/src/main/webapp/user-form.jsp @@ -0,0 +1,82 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + + + 用户表单 - Struts2 + + + +

添加用户编辑用户

+ +
+ 实验任务卡 +
    +
  • 试着新增一个完整用户,提交后观察为什么回到列表页
  • +
  • 再故意填一个不合理年龄,看当前脚手架是否已经做服务端校验
  • +
  • 思考:如果要做更严谨校验,你会把规则放在 Action、拦截器,还是 XML/注解里?
  • +
+
+ +
+ 快速填充示例 +
+ + +
+
+ + + + +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ +
+ 学习点 +
    +
  • 表单字段名 user.name / user.email / user.age 会映射到嵌套对象
  • +
  • 当进入编辑页时,Action 会先根据 id 找到已有对象并回填
  • +
  • 提交成功后通过 redirectAction 返回列表页,避免刷新重复提交
  • +
+
+ +

← 返回用户列表

+ + + + diff --git a/src/main/webapp/user-list.jsp b/src/main/webapp/user-list.jsp new file mode 100644 index 0000000..5f47a12 --- /dev/null +++ b/src/main/webapp/user-list.jsp @@ -0,0 +1,80 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + + + 用户管理 - Struts2 CRUD 示例 + + + +

👥 用户管理 - Struts2 CRUD 示例

+ +
+ 实验任务卡 +
    +
  • 先新增一个用户,观察表单提交后为什么会回到列表页
  • +
  • 再编辑一个用户,体会 Struts2 如何把已有数据回填到表单
  • +
  • 最后删除一个用户,理解 redirectAction 的使用场景
  • +
+
+ +
+
当前用户数
+
演示模式内存列表
+
学习重点CRUD 流程
+
+ +

+ 添加用户

+ + + + + + + + + + + + + + + + + + +
ID姓名邮箱年龄操作
+ 编辑 + 删除 +
+ +
+ 学习点 +
    +
  • <s:iterator> 遍历集合
  • +
  • redirectAction 结果类型实现 PRG 模式
  • +
  • 同一个 Action 通过不同 method 处理 list/add/edit/update/delete
  • +
  • 这里的数据存在内存里,重启后会恢复初始样本
  • +
+
+ +

← 返回学习中心

+ +