jsp actions 使用您可以動態的插入一個文件,重用javabeans組件,前進到另一個頁面,或為java 插件生成一個html。可以使用的action 有:
(1) jsp:include --在頁面被請求時包含進一個文件。
(2) jsp:usebean--找到或實例化一個javabean。
(3) jsp:setproperty--設置一個javabean屬性。
(4) jsp:getproperty--將javabean的屬性插入到輸出。
(5) jsp:forward--讓請求者可以向前到一個新的頁面。
(6) jsp:plugin--用object或embed標簽為java plugins生成特定的瀏覽器的代碼。
1、jsp:include action
這個action使您可以在即將生成的頁面上包含進一些文件:
<jsp:include page="relative url" flush="true" />
與include directive不同,這個action是在頁面被請求時才將文件包含進來,而,include directive則是在jsp頁面被轉換為servlet時包含文件。為了提高效率,include action做了一點小小的犧牲,即,它不允許被包含的頁面含有一般的jsp代碼(例如,不可設置http頭),但是,它具有顯著的靈活性,如下面的jsp 代碼,它實現將四個不同的片段插入如下的頁面。每一次當標題改變的時候,您僅需修改這四個文件而無須更改主要的jsp 頁面。
whatsnew.jsp
<html>
<head>
<title> jsp教程</title>
<body >
<center>
<table border=5 bgcolor="#ef8429">
<tr><th class="title"> what"s new at chinese comic sites</table>
</center>
<p>
here is a summary of our four most recent news stories:
<ol>
<li><jsp:include page="news/item1.html" flush="true"/>
<li><jsp:include page="news/item2.html" flush="true"/>
<li><jsp:include page="news/item3.html" flush="true"/>
<li><jsp:include page="news/item4.html" flush="true"/>
</ol>
</body>
</html>
當然您可以定義自己的html文件,但有一點請注意:
您應該將文件放到您的jsp目錄下的news目錄內。
新聞熱點
疑難解答