2000-12-13· 清枫·yesky
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目录内。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器