Files
struts2-scaffold/target/struts2-scaffold-1.0.0/learn.jsp

112 lines
4.4 KiB
Plaintext
Raw Normal View History

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<head>
<title>Struts2 学习中心</title>
<style>
body { font-family: Arial, sans-serif; max-width: 900px; margin: 50px auto; padding: 20px; }
h1 { color: #e74c3c; }
h2 { color: #3498db; border-bottom: 2px solid #3498db; padding-bottom: 10px; }
.card { background: #f5f5f5; padding: 20px; border-radius: 8px; margin: 20px 0; }
.card h3 { margin-top: 0; }
ul { line-height: 2; }
a { color: #3498db; text-decoration: none; }
a:hover { text-decoration: underline; }
.btn { display: inline-block; background: #3498db; color: white; padding: 10px 20px;
border-radius: 5px; margin: 5px; }
.btn:hover { text-decoration: none; background: #2980b9; }
.btn-green { background: #27ae60; }
.btn-purple { background: #9b59b6; }
code { background: #eee; padding: 2px 6px; border-radius: 3px; }
.lab { background:#fff7e6; border-left:4px solid #fa8c16; padding:15px; border-radius:8px; margin:20px 0; }
.quick-tools { display:flex; gap:10px; flex-wrap:wrap; margin-top:10px; }
</style>
</head>
<body>
<h1>🎓 Struts2 学习中心</h1>
<div class="lab">
<strong>🧪 学习任务卡</strong>
<ul>
<li>先点“拦截器演示”,观察执行统计和链路顺序</li>
<li>再点“计算器”,故意输入非法值体验 Struts2 验证</li>
<li>最后点“用户管理”,理解 Action + JSP + 表单提交流程</li>
</ul>
<div class="quick-tools">
<a class="btn btn-purple" href="interceptor">直接去拦截器实验</a>
<a class="btn" href="calc">直接去计算器实验</a>
<a class="btn btn-green" href="user">直接去用户管理实验</a>
</div>
</div>
<div class="card">
<h3>🛡️ 拦截器 (核心特性)</h3>
<p>拦截器是 Struts2 最强大的特性之一,基于责任链模式实现 AOP。</p>
<div>
<a class="btn btn-purple" href="interceptor">拦截器演示</a>
</div>
<ul>
<li><a href="interceptor">LoggingInterceptor</a> - 日志记录</li>
<li><a href="interceptor">TimingInterceptor</a> - 性能计时</li>
<li><a href="interceptor">RateLimitInterceptor</a> - IP 限流</li>
<li><a href="interceptor">ValidationInterceptor</a> - 参数验证</li>
<li><a href="interceptor">MonitorInterceptor</a> - 状态监控</li>
</ul>
</div>
<div class="card">
<h3>📝 基础示例</h3>
<div>
<a class="btn" href="hello">Hello World</a>
<a class="btn" href="calc">计算器</a>
<a class="btn btn-green" href="user">用户管理</a>
</div>
</div>
<h2>📚 学习路径</h2>
<div class="card">
<h3>1. MVC 架构</h3>
<ul>
<li><strong>Model:</strong> Action 类 + JavaBean</li>
<li><strong>View:</strong> JSP + Struts 标签库</li>
<li><strong>Controller:</strong> StrutsPrepareAndExecuteFilter</li>
</ul>
</div>
<div class="card">
<h3>2. 拦截器机制</h3>
<ul>
<li><code>Interceptor</code> 接口: init() → intercept() → destroy()</li>
<li><code>interceptor-stack</code>: 组合多个拦截器</li>
<li>执行顺序: 责任链模式(先入后出)</li>
</ul>
</div>
<div class="card">
<h3>3. OGNL 表达式</h3>
<ul>
<li><code>&lt;s:property value="name"/&gt;</code> - 输出属性</li>
<li><code>&lt;s:iterator value="list"&gt;</code> - 遍历集合</li>
<li><code>#request.key</code> - 访问 request</li>
</ul>
</div>
<div class="card">
<h3>4. 项目结构</h3>
<pre>
├── src/main/java/com/example/struts2/
│ ├── action/ # Action 类
│ └── interceptor/ # 自定义拦截器
├── src/main/resources/
│ └── struts.xml # 核心配置
└── src/main/webapp/
├── WEB-INF/web.xml # Servlet 配置
└── *.jsp # 视图页面
</pre>
</div>
<p><a href="/">← 返回首页</a></p>
</body>
</html>