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>