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,58 +1,102 @@
<%@ 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>User Form - 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, #f97316 0%, #fb923c 50%, #ffedd5 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: 820px;
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);
}
.eyebrow {
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #ea580c;
font-weight: 800;
}
h1 { margin: 10px 0 12px; }
p { margin: 0; color: #6c5545; line-height: 1.85; }
.field { margin-top: 16px; }
label { display: block; margin-bottom: 8px; font-weight: 700; color: #4c3422; }
input {
width: 100%;
padding: 13px 14px;
border-radius: 14px;
border: 1px solid #ead8ca;
font: inherit;
}
h2 { color: #f5576c; margin-bottom: 20px; }
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 8px; color: #555; }
input { width: 100%; padding: 12px; border: 2px solid #e0e0e0; border-radius: 8px; }
button {
width: 100%;
margin-top: 18px;
padding: 14px;
background: #f5576c;
border: 0;
border-radius: 14px;
background: linear-gradient(135deg, #ea580c, #fb923c);
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 800;
cursor: pointer;
}
.error { color: #c2410c; 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: #fff1e8;
color: #c2410c;
text-decoration: none;
font-weight: 700;
}
</style>
</head>
<body>
<div class="container">
<div class="card">
<h2>👤 用户信息提交</h2>
<s:form action="submitUser">
<div class="form-group">
<label>用户名</label>
<s:textfield name="username"/>
</div>
<div class="form-group">
<label>邮箱</label>
<s:textfield name="email"/>
</div>
<div class="form-group">
<label>电话</label>
<s:textfield name="phone"/>
</div>
<button type="submit">提交</button>
</s:form>
<div class="shell">
<div class="eyebrow">User action</div>
<h1>Capture a user profile through Struts binding</h1>
<p>This form now demonstrates a more realistic user intake flow with field errors and a structured success screen.</p>
<s:form action="submitUser" method="post" namespace="/">
<div class="field">
<label for="username">Username</label>
<s:textfield id="username" name="username" placeholder="platform-owner"/>
<div class="error"><s:fielderror fieldName="username"/></div>
</div>
<div class="field">
<label for="email">Email</label>
<s:textfield id="email" name="email" placeholder="platform@example.com"/>
<div class="error"><s:fielderror fieldName="email"/></div>
</div>
<div class="field">
<label for="phone">Phone</label>
<s:textfield id="phone" name="phone" placeholder="13800000000"/>
<div class="error"><s:fielderror fieldName="phone"/></div>
</div>
<button type="submit">Submit profile</button>
</s:form>
<div class="links">
<a class="link-btn" href="../index.jsp">Back to portal</a>
<a class="link-btn" href="login.jsp">Open login demo</a>
</div>
</div>
</body>
</html>
</html>

View File

@@ -1,94 +1,176 @@
<%@ 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>Login Demo - Struts2 Demo Lab</title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 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, #122c63 0%, #1464c7 52%, #4db5ff 100%);
}
.login-box {
background: white;
padding: 40px;
border-radius: 15px;
box-shadow: 0 15px 50px rgba(0,0,0,0.3);
width: 400px;
.shell {
width: min(1040px, 100%);
display: grid;
grid-template-columns: 1fr 420px;
gap: 18px;
}
h2 { color: #333; margin-bottom: 30px; text-align: center; }
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 8px; color: #555; font-weight: 500; }
input {
width: 100%;
padding: 12px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 14px;
transition: border-color 0.3s;
.panel {
background: rgba(255,255,255,0.95);
border-radius: 28px;
padding: 28px;
box-shadow: 0 24px 60px rgba(0,0,0,0.22);
}
.eyebrow {
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #1464c7;
font-weight: 800;
}
h1, h2 { margin: 10px 0 12px; }
p { margin: 0; color: #566a80; line-height: 1.85; }
.note {
margin-top: 18px;
padding: 16px;
border-radius: 18px;
background: #edf5ff;
border: 1px solid #d7e5f7;
}
.stats {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
margin-top: 18px;
}
.stat {
padding: 14px;
border-radius: 18px;
border: 1px solid #d7e5f7;
background: #f8fbff;
}
.stat strong { display: block; margin-bottom: 6px; }
.field {
margin-bottom: 16px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 700;
color: #1f3650;
}
input {
width: 100%;
padding: 13px 14px;
border-radius: 14px;
border: 1px solid #d6e1ed;
font: inherit;
}
input:focus { border-color: #667eea; outline: none; }
.error { color: #e53935; font-size: 0.85em; margin-top: 5px; }
.error-field { border-color: #e53935 !important; }
button {
width: 100%;
padding: 14px;
background: #667eea;
border: 0;
border-radius: 14px;
background: linear-gradient(135deg, #1464c7, #3d8ef6);
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 800;
cursor: pointer;
transition: background 0.3s;
}
button:hover { background: #764ba2; }
.tips {
background: #e8f5e9;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
font-size: 0.9em;
color: #2e7d32;
.error {
color: #c53d3d;
font-size: 13px;
margin-top: 6px;
}
.action-error {
margin: 0 0 16px;
padding: 14px;
border-radius: 14px;
background: #fff1f1;
color: #b63a3a;
border: 1px solid #f1c4c4;
}
.links {
display: flex;
gap: 10px;
flex-wrap: wrap;
margin-top: 18px;
}
.link-btn {
display: inline-flex;
padding: 10px 14px;
border-radius: 999px;
background: #edf5ff;
color: #1464c7;
text-decoration: none;
font-weight: 700;
}
@media (max-width: 860px) {
.shell { grid-template-columns: 1fr; }
}
a { color: #667eea; text-decoration: none; }
</style>
</head>
<body>
<div class="login-box">
<h2>🔐 用户登录</h2>
<div class="tips">
<strong>测试账号:</strong> admin / 123456
</div>
<!-- Struts2 表单标签 -->
<s:form action="login" method="post" namespace="/">
<div class="form-group">
<label>用户名</label>
<s:textfield name="username" placeholder="请输入用户名" cssClass="%{hasErrors('username') ? 'error-field' : ''}"/>
<s:fielderror fieldName="username"/>
<div class="shell">
<section class="panel">
<div class="eyebrow">Demo login</div>
<h1>Login flow with validation and guided next steps</h1>
<p>This page turns the original login example into a better teaching demo. It keeps validation close to the form, shows a reusable credentials note, and links to follow-up demos after success.</p>
<div class="note">
<strong>Demo credentials</strong>
<p style="margin-top: 8px;">Username: <code>admin</code><br/>Password: <code>123456</code></p>
</div>
<div class="form-group">
<label>密码</label>
<s:password name="password" placeholder="请输入密码" showPassword="true"/>
<s:fielderror fieldName="password"/>
<div class="stats">
<div class="stat">
<strong>What this demonstrates</strong>
<span>Action execution, field validation, action errors, and result routing.</span>
</div>
<div class="stat">
<strong>Suggested next route</strong>
<span>After login, continue with the user form or validation demo.</span>
</div>
</div>
<!-- 显示 Action 错误消息 -->
<s:actionerror/>
<button type="submit">登录</button>
</s:form>
<p style="text-align:center;margin-top:20px;">
<a href="index.jsp">← 返回首页</a>
</p>
<div class="links">
<a class="link-btn" href="../index.jsp">Back to portal</a>
<a class="link-btn" href="../hello?name=Team">Run hello action</a>
</div>
</section>
<section class="panel">
<div class="eyebrow">Sign in</div>
<h2>Enter the demo account</h2>
<s:if test="hasActionErrors()">
<div class="action-error"><s:actionerror/></div>
</s:if>
<s:form action="login" method="post" namespace="/">
<div class="field">
<label for="username">Username</label>
<s:textfield id="username" name="username" placeholder="admin"/>
<div class="error"><s:fielderror fieldName="username"/></div>
</div>
<div class="field">
<label for="password">Password</label>
<s:password id="password" name="password" placeholder="123456" showPassword="true"/>
<div class="error"><s:fielderror fieldName="password"/></div>
</div>
<button type="submit">Continue to the dashboard</button>
</s:form>
</section>
</div>
</body>
</html>
</html>

View File

@@ -1,44 +1,111 @@
<%@ 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>Success Dashboard - 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;
padding: 24px;
font-family: "Aptos", "Segoe UI", "Microsoft YaHei", sans-serif;
background: linear-gradient(135deg, #0d8f7c 0%, #31c48d 55%, #d4f7e7 100%);
color: #123028;
}
.shell {
max-width: 1080px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
gap: 18px;
}
.card {
background: white;
padding: 40px;
border-radius: 15px;
text-align: center;
box-shadow: 0 15px 50px rgba(0,0,0,0.3);
background: rgba(255,255,255,0.94);
border-radius: 28px;
padding: 28px;
box-shadow: 0 24px 60px rgba(0,0,0,0.18);
}
h1 { color: #11998e; font-size: 3em; margin-bottom: 20px; }
p { color: #666; font-size: 1.2em; margin-bottom: 30px; }
.btn {
display: inline-block;
padding: 12px 30px;
background: #11998e;
color: white;
.eyebrow {
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #0d8f7c;
font-weight: 800;
}
h1, h2 { margin: 10px 0 12px; }
p { margin: 0; color: #446056; line-height: 1.85; }
.stats {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 12px;
margin-top: 18px;
}
.stat {
padding: 16px;
border-radius: 18px;
border: 1px solid #d7eee6;
background: #f7fcfa;
}
.stat span { display: block; color: #5f7f75; font-size: 12px; margin-bottom: 6px; }
.stat strong { font-size: 22px; }
.links {
display: flex;
gap: 10px;
flex-wrap: wrap;
margin-top: 18px;
}
.link-btn {
display: inline-flex;
padding: 10px 14px;
border-radius: 999px;
background: #e8f8f2;
color: #0d8f7c;
text-decoration: none;
border-radius: 25px;
transition: transform 0.3s;
font-weight: 700;
}
@media (max-width: 760px) {
.stats { grid-template-columns: 1fr; }
}
.btn:hover { transform: scale(1.05); }
</style>
</head>
<body>
<div class="card">
<h1>✅ 登录成功!</h1>
<p>欢迎回来,<s:property value="username"/></p>
<a href="../index.jsp" class="btn">返回首页</a>
<div class="shell">
<section class="card">
<div class="eyebrow">Result</div>
<h1>Demo flow completed successfully</h1>
<p>This page now acts as a shared success dashboard for multiple form-based actions. It makes the result screen more useful than a single success line.</p>
</section>
<section class="card">
<div class="eyebrow">Current submission</div>
<h2><s:property value="displayName != null ? displayName : username"/></h2>
<p><s:property value="recommendation != null ? recommendation : profileStage"/></p>
<div class="stats">
<div class="stat">
<span>Username</span>
<strong><s:property value="username" default="demo-user"/></strong>
</div>
<div class="stat">
<span>Role or stage</span>
<strong><s:property value="role != null ? role : profileStage"/></strong>
</div>
<div class="stat">
<span>Timestamp</span>
<strong><s:property value="loginTime != null ? loginTime : submittedAt"/></strong>
</div>
</div>
<div class="links">
<a class="link-btn" href="../index.jsp">Back to portal</a>
<a class="link-btn" href="form.jsp">Open user form</a>
<a class="link-btn" href="../validation/form.jsp">Run validation demo</a>
<a class="link-btn" href="../upload/index.jsp">Open upload demo</a>
</div>
</section>
</div>
</body>
</html>
</html>