52 lines
2.2 KiB
Plaintext
52 lines
2.2 KiB
Plaintext
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>AJAX and JSON Guide</title>
|
|
<style>
|
|
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; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<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>
|
|
|
|
<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>
|
|
|
|
<pre>public class AjaxAction extends ActionSupport {
|
|
private boolean success;
|
|
private String message;
|
|
private List<User> users;
|
|
|
|
public String execute() {
|
|
success = true;
|
|
message = "Mock AJAX response";
|
|
return SUCCESS;
|
|
}
|
|
}</pre>
|
|
|
|
<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>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|