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,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>