平時我們加載Action的時候都是提交表單,或者點擊按鈕以後才能發起Action請求。
現在我要實現一個功能:打開一個網站的首頁從數據庫中立刻讀取多條不同表中的數據顯示在頁面上。這個時候要發起多個Action請求,而且還是要自動發起請求。
實現的效果如圖所示:
實現的核心代碼如下:利用iframe標籤的src指向Action。加載頁面的時候會自動加載Action
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>KindEditor JSP</title>
</head>
<body>
<iframe id="mainframe" src="findAction.action" name="mainframe" frameborder="0" scrolling="no" width="1000px" height="100px"></iframe>
<iframe id="mainframe" src="findAction2.action" name="mainframe" frameborder="0" scrolling="no" width="1000px" height="700px" ></iframe>
</body>
</html>