Files
struts2-demo/web/demo/ajax/index.jsp

52 lines
2.2 KiB
Plaintext
Raw Normal View History

2026-03-18 15:18:30 +08:00
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
2026-03-18 18:12:20 +08:00
<html lang="en">
2026-03-18 15:18:30 +08:00
<head>
<meta charset="UTF-8">
2026-03-18 18:12:20 +08:00
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AJAX and JSON Guide</title>
2026-03-18 15:18:30 +08:00
<style>
2026-03-18 18:12:20 +08:00
body { margin: 0; padding: 24px; font-family: "Aptos", "Segoe UI", sans-serif; background: linear-gradient(135deg, #122c63, #1464c7); }
.shell { max-width: 980px; margin: 0 auto; background: rgba(255,255,255,0.96); border-radius: 28px; padding: 28px; box-shadow: 0 24px 60px rgba(0,0,0,0.18); }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: #1464c7; font-weight: 800; }
h1, h2 { margin: 10px 0 12px; }
p, li { color: #53667d; line-height: 1.9; }
pre { background: #101827; color: #d9e7ff; padding: 18px; border-radius: 18px; overflow-x: auto; }
.links { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.btn { display: inline-flex; padding: 10px 14px; border-radius: 999px; text-decoration: none; font-weight: 700; background: #e8f2ff; color: #1464c7; }
2026-03-18 15:18:30 +08:00
</style>
</head>
<body>
2026-03-18 18:12:20 +08:00
<div class="shell">
<div class="eyebrow">Guide</div>
<h1>Returning JSON from Struts2 actions</h1>
<p>The demo now includes both an action-level JSON response and a REST-style JSON route. That makes it easier to compare MVC pages with lightweight API payloads.</p>
2026-03-18 15:18:30 +08:00
2026-03-18 18:12:20 +08:00
<h2>What the action returns</h2>
<ul>
<li>A <code>success</code> flag.</li>
<li>A short message describing the payload.</li>
<li>Sample user records that can be consumed by AJAX.</li>
</ul>
2026-03-18 15:18:30 +08:00
2026-03-18 18:12:20 +08:00
<pre>public class AjaxAction extends ActionSupport {
private boolean success;
private String message;
private List&lt;User&gt; users;
public String execute() {
success = true;
message = "Mock AJAX response";
return SUCCESS;
}
2026-03-18 15:18:30 +08:00
}</pre>
2026-03-18 18:12:20 +08:00
<div class="links">
<a class="btn" href="../../ajax">Open action JSON</a>
<a class="btn" href="../../api/users">Open REST JSON</a>
<a class="btn" href="../../index.jsp">Back to portal</a>
2026-03-18 15:18:30 +08:00
</div>
</div>
</body>
2026-03-18 18:12:20 +08:00
</html>