前端用 `
// 前端 jQuery
$.post("queryAction", params, function(data) {
// data 為 JSON 或 HTML 片段
$("#iframeContainer").html(data); // 或填充表格
});
Action 返回 JSON/String,不配置 `
public void query(HttpServletResponse response) throws IOException {
List<Item> list = service.query();
response.setContentType("application/json;charset=UTF-8");
response.getWriter().write(JSON.toJSONString(list));
}
struts.xml 不配置該 action 的 `
<form action="queryAction" target="myIframe" method="post">
<input name="param" />
<button type="submit">查詢</button>
</form>
<iframe name="myIframe" src="about:blank"></iframe>
Action 正常返回 JSP 頁面,瀏覽器自動在 iframe 中渲染。