Files
struts2-demo/web/WEB-INF/views/validation/form.jsp

134 lines
5.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>字段校验实验 - Struts2 学习实验台</title>
<style>
body {
margin: 0;
min-height: 100vh;
padding: 24px;
font-family: "Aptos", "Segoe UI", "Microsoft YaHei", sans-serif;
background: linear-gradient(135deg, #db2777 0%, #f472b6 55%, #ffe4f1 100%);
}
.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);
}
.eyebrow {
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #db2777;
font-weight: 800;
}
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;
border: 0;
border-radius: 14px;
background: linear-gradient(135deg, #db2777, #f472b6);
color: white;
font-size: 16px;
font-weight: 800;
cursor: pointer;
}
.error { color: #c0265d; font-size: 13px; margin-top: 6px; }
.note {
margin-top: 18px;
padding: 16px;
border-radius: 18px;
background: #fff3f8;
border: 1px solid #f3d8e6;
}
.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="shell">
<div class="eyebrow">受保护校验页</div>
<h1>在业务执行前,先把输入规则讲清楚</h1>
<p>这个实验页专门用来讲 Struts2 的 <code>validate()</code>。你可以故意输错,再看字段错误如何被带回到原页面。</p>
<s:if test="#session.demoUser == null">
<div class="note">
<strong>当前未登录</strong>
<p style="margin-top: 8px;">校验页也已经接入 Session 保护。请先登录,再体验校验失败和成功两种状态。</p>
</div>
<div class="links">
<a class="link-btn" href="../loginPage.action">先去登录</a>
<a class="link-btn" href="../index.action">返回门户</a>
</div>
</s:if>
<s:else>
<div class="note">
<strong>建议观察点</strong>
<p style="margin-top: 8px;">先故意输入一个短用户名、错误邮箱和超范围年龄,再修正后重新提交,对比两次页面反馈。</p>
</div>
<s:form action="validate" method="post" namespace="/">
<div class="field">
<label for="username">用户名3 到 20 字符)</label>
<s:textfield id="username" name="username" placeholder="release-manager"/>
<div class="error"><s:fielderror fieldName="username"/></div>
</div>
<div class="field">
<label for="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">年龄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">简介</label>
<s:textarea id="bio" name="bio" placeholder="描述角色、经验或当前负责的平台方向。"/>
<div class="error"><s:fielderror fieldName="bio"/></div>
</div>
<button type="submit">提交并查看校验结果</button>
</s:form>
<div class="links">
<a class="link-btn" href="../dashboard.action">返回仪表盘</a>
<a class="link-btn" href="../uploadPage.action">继续看上传页</a>
</div>
</s:else>
</div>
</body>
</html>