feat: expand struts demo lab

This commit is contained in:
Codex
2026-03-18 18:12:20 +08:00
parent 1f60832445
commit fba7b0497f
25 changed files with 1847 additions and 1447 deletions

View File

@@ -1,103 +1,109 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>表单验证 - Struts2 Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Validation Demo - Struts2 Demo Lab</title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
body {
margin: 0;
min-height: 100vh;
padding: 20px;
padding: 24px;
font-family: "Aptos", "Segoe UI", "Microsoft YaHei", sans-serif;
background: linear-gradient(135deg, #db2777 0%, #f472b6 55%, #ffe4f1 100%);
}
.container { max-width: 600px; margin: 0 auto; }
.card {
background: white;
padding: 30px;
border-radius: 15px;
box-shadow: 0 15px 50px rgba(0,0,0,0.3);
.shell {
max-width: 900px;
margin: 0 auto;
background: rgba(255,255,255,0.95);
border-radius: 28px;
padding: 28px;
box-shadow: 0 24px 60px rgba(0,0,0,0.18);
}
h2 { color: #f5576c; margin-bottom: 20px; }
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 8px; color: #555; font-weight: 500; }
input, textarea {
width: 100%;
padding: 12px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 14px;
.eyebrow {
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #db2777;
font-weight: 800;
}
input:focus, textarea:focus { border-color: #f5576c; outline: none; }
.error { color: #e53935; font-size: 0.85em; margin-top: 5px; }
h1 { margin: 10px 0 12px; }
p { margin: 0; color: #6e5565; line-height: 1.85; }
.field { margin-top: 16px; }
label { display: block; margin-bottom: 8px; font-weight: 700; color: #4a223b; }
input, textarea {
width: 100%;
padding: 13px 14px;
border-radius: 14px;
border: 1px solid #ecd6e0;
font: inherit;
}
textarea { resize: vertical; min-height: 120px; }
button {
width: 100%;
margin-top: 18px;
padding: 14px;
background: #f5576c;
border: 0;
border-radius: 14px;
background: linear-gradient(135deg, #db2777, #f472b6);
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 800;
cursor: pointer;
}
button:hover { background: #e91e63; }
.info {
background: #e3f2fd;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
}
code {
background: #f5f5f5;
padding: 2px 6px;
border-radius: 3px;
color: #e91e63;
.error { color: #c0265d; font-size: 13px; margin-top: 6px; }
.links { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.link-btn {
display: inline-flex;
padding: 10px 14px;
border-radius: 999px;
background: #fff0f7;
color: #db2777;
text-decoration: none;
font-weight: 700;
}
</style>
</head>
<body>
<div class="container">
<div class="card">
<h2>📝 表单验证示例</h2>
<div class="info">
<strong>验证方式:</strong>
<ul style="margin:10px 0 0 20px;">
<li>在 Action 中重写 <code>validate()</code> 方法</li>
<li>使用 XML 验证文件 (ActionName-validation.xml)</li>
<li>使用注解验证 (@Required, @IntRange 等)</li>
</ul>
<div class="shell">
<div class="eyebrow">Validation demo</div>
<h1>Test field validation with realistic profile inputs</h1>
<p>This form shows how Struts2 can keep validation close to the action while still rendering a friendlier teaching page.</p>
<s:form action="validate" method="post" namespace="/">
<div class="field">
<label for="username">Username (3-20 chars)</label>
<s:textfield id="username" name="username" placeholder="release-manager"/>
<div class="error"><s:fielderror fieldName="username"/></div>
</div>
<s:form action="validate" method="post">
<div class="form-group">
<label>用户名 (3-20字符)</label>
<s:textfield name="username"/>
<s:fielderror fieldName="username"/>
</div>
<div class="form-group">
<label>邮箱</label>
<s:textfield name="email"/>
<s:fielderror fieldName="email"/>
</div>
<div class="form-group">
<label>年龄 (18-60)</label>
<s:textfield name="age"/>
<s:fielderror fieldName="age"/>
</div>
<div class="form-group">
<label>个人简介</label>
<s:textarea name="bio" rows="4"/>
</div>
<s:actionerror/>
<button type="submit">提交验证</button>
</s:form>
<div class="field">
<label for="email">Email</label>
<s:textfield id="email" name="email" placeholder="release@example.com"/>
<div class="error"><s:fielderror fieldName="email"/></div>
</div>
<div class="field">
<label for="age">Age (18-60)</label>
<s:textfield id="age" name="age" placeholder="30"/>
<div class="error"><s:fielderror fieldName="age"/></div>
</div>
<div class="field">
<label for="bio">Bio</label>
<s:textarea id="bio" name="bio" placeholder="Describe the role, strengths, or current platform focus."/>
<div class="error"><s:fielderror fieldName="bio"/></div>
</div>
<button type="submit">Validate this profile</button>
</s:form>
<div class="links">
<a class="link-btn" href="../index.jsp">Back to portal</a>
<a class="link-btn" href="../demo/ajax/index.jsp">Read the JSON guide</a>
</div>
</div>
</body>
</html>
</html>

View File

@@ -1,54 +1,86 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>验证成功 - Struts2 Demo</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Validation Summary - Struts2 Demo Lab</title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
body {
margin: 0;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 24px;
font-family: "Aptos", "Segoe UI", "Microsoft YaHei", sans-serif;
background: linear-gradient(135deg, #db2777 0%, #f472b6 55%, #ffe4f1 100%);
}
.card {
background: white;
padding: 40px;
border-radius: 15px;
text-align: center;
min-width: 400px;
width: min(820px, 100%);
background: rgba(255,255,255,0.95);
border-radius: 28px;
padding: 28px;
box-shadow: 0 24px 60px rgba(0,0,0,0.18);
}
h1 { color: #11998e; margin-bottom: 20px; }
.data {
background: #f5f5f5;
padding: 20px;
border-radius: 8px;
text-align: left;
margin: 20px 0;
.eyebrow {
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #db2777;
font-weight: 800;
}
.data p { margin: 10px 0; }
.btn {
display: inline-block;
padding: 12px 30px;
background: #11998e;
color: white;
h1 { margin: 10px 0 12px; }
p { margin: 0; color: #6a5060; line-height: 1.85; }
.stats {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
margin-top: 18px;
}
.stat {
padding: 16px;
border-radius: 18px;
background: #fff5fa;
border: 1px solid #f1d8e5;
}
.stat span { display: block; font-size: 12px; color: #8a697b; margin-bottom: 6px; }
.stat strong { font-size: 18px; }
.links { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.link-btn {
display: inline-flex;
padding: 10px 14px;
border-radius: 999px;
background: #fff0f7;
color: #db2777;
text-decoration: none;
border-radius: 25px;
font-weight: 700;
}
@media (max-width: 720px) {
.stats { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="card">
<h1>✅ 验证通过!</h1>
<div class="data">
<p><strong>用户名:</strong> <s:property value="username"/></p>
<p><strong>邮箱:</strong> <s:property value="email"/></p>
<p><strong>年龄:</strong> <s:property value="age"/></p>
<p><strong>简介:</strong> <s:property value="bio"/></p>
<div class="eyebrow">Validation summary</div>
<h1>Profile validation passed</h1>
<p>The action accepted the submitted fields and calculated a simple profile band for the demo.</p>
<div class="stats">
<div class="stat"><span>Username</span><strong><s:property value="username"/></strong></div>
<div class="stat"><span>Email</span><strong><s:property value="email"/></strong></div>
<div class="stat"><span>Age</span><strong><s:property value="age"/></strong></div>
<div class="stat"><span>Profile band</span><strong><s:property value="scoreBand"/></strong></div>
<div class="stat"><span>Submitted at</span><strong><s:property value="submittedAt"/></strong></div>
<div class="stat"><span>Bio</span><strong><s:property value="bio" default="No bio submitted."/></strong></div>
</div>
<div class="links">
<a class="link-btn" href="form.jsp">Try validation again</a>
<a class="link-btn" href="../index.jsp">Back to portal</a>
</div>
<a href="form.jsp" class="btn">继续测试</a>
</div>
</body>
</html>
</html>