forked from admin/struts2-demo
103 lines
3.4 KiB
Plaintext
103 lines
3.4 KiB
Plaintext
|
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||
|
|
<%@ taglib prefix="s" uri="/struts-tags" %>
|
||
|
|
<!DOCTYPE html>
|
||
|
|
<html>
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8">
|
||
|
|
<title>表单验证 - Struts2 Demo</title>
|
||
|
|
<style>
|
||
|
|
body {
|
||
|
|
font-family: 'Segoe UI', sans-serif;
|
||
|
|
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||
|
|
min-height: 100vh;
|
||
|
|
padding: 20px;
|
||
|
|
}
|
||
|
|
.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);
|
||
|
|
}
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
input:focus, textarea:focus { border-color: #f5576c; outline: none; }
|
||
|
|
.error { color: #e53935; font-size: 0.85em; margin-top: 5px; }
|
||
|
|
button {
|
||
|
|
width: 100%;
|
||
|
|
padding: 14px;
|
||
|
|
background: #f5576c;
|
||
|
|
color: white;
|
||
|
|
border: none;
|
||
|
|
border-radius: 8px;
|
||
|
|
font-size: 16px;
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
</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>
|
||
|
|
|
||
|
|
<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>
|
||
|
|
</div>
|
||
|
|
</body>
|
||
|
|
</html>
|