一。用于执行对页面的请求,并将响应结果的客户端代码存储在JSP变量中。
有三种使用方法:
1. 使用forward属性指定forward名称
<bean:include id=”search forward=”forward”/>
2. 使用href属性指定绝对URL
<bean:include id=”search” href=”http://www.google.com” />
3. 使用page属性指定相对于应用程序的URL
<bean:include id=”search” page=”/search.jsp”/>
使用bean:write输出时要将其filter属性设置为false才能显示正确信息,否则显示客户端源代码
二。 <bean:inlcude>标签:与<jsp:include>标记基本相同,都是把被包含的文件先执行,再包含;
区别在于: <jsp:include>直接把包含的文件显示到页面上,<bean:include>标记是把内容保存到一个局部变量中,然后再处理。
<bean:include>常用属性为 id和forward、page、href三者之一。
使用这个标记可以包含外部服务器的获取XML到本地处理。
用于加载Web应用程序资源的内容并将其以String对象存储在页面范围和本地范围内的JSP变量中。另外,你可以选择指定是否只想要资源的java.io.InputStream对象的引用而不是将其内容保存在String对象中
Web应用程序资源是那些作为Web应用程序的一部分而打包的文件。如:
如果你的Web应用程序位于名为c:\tomcat\strutssample的目录中,并有以下文件:
l c:\tomcat\strutssample\index.jsp
l c:\tomcat\strutssample\WEB-INF\struts-config.xml
那么你就可以将index.jsp作为“/index.jsp”来访问。请注意,WEB应用程序资源的路径与该应用程序相关,且必须用斜杠(/)开头。
如果加载资源错误,则在运行resource标记时会抛出一个JspException异常。]
用resource标记加载struts-config.xml的示例:
<bean:resource id=”strutsConfig” name=”/WEB-INF/struts-config.xml”/>
访问:
Struts Config file contents:<%=strutsConfig%>
或
Struts Config file contents:<bean:write name=”strutsConfig”/>
以下代码帮说明如何使用资源标记来为WEB应用程序资源获得一个java.io.InputStream的引用。
<bean:resource id=”strutsConfig” input=”true” name=”/WEB-INF/struts-config.xml”/>
input属性接受任何的值。只要存在值,java.io.InputStream引用将被存储在JSP变量中,而不是包含WEB资源内容的String对象。
你可以使用bean:resource标记加载web应用程序资源的内容,比用Scriplet更简洁。
--------------------------------------------------------------------------------------------------------------------------------
header.jsp
<html:html lang="true">
<head>
<html:base />
<title>header.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<bean:define id="empId" value="ssssssssssssssssssssssssssssss"/>
<bean:write name="empId"/>
</body>
</html:html>
resourceAndinclude.jsp
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<title>resourceAndinclude.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
bean:resource标签:
<hr>
<bean:resource id="head" name="/header.jsp"/>
<bean:write name="head" />
<hr/>
bean:resource标签true:
<hr>
<bean:resource id="head" name="/header.jsp"/>
<bean:write name="head" filter="true"/>
<hr/>
bean:resource标签false:
<hr>
<bean:resource id="head" name="/header.jsp"/>
<bean:write name="head" filter="false"/>
<hr/>
bean:include标签:
<hr>
<bean:include id="head1" page="/header.jsp"/>
<bean:write name="head1"/>
<hr/>
bean:include标签true:
<hr>
<bean:include id="head1" page="/header.jsp"/>
<bean:write name="head1" filter="true"/>
<hr/>
bean:include标签false:
<hr>
<bean:include id="head1" page="/header.jsp"/>
<bean:write name="head1" filter="false"/>
</body>
</html:html>
-------------------------------------------显示的结果
bean:resource标签: <%@ page language="java" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %> <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:html lang="true"> <head> <html:base /> <title>header.jsp</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <bean:define id="empId" value="ssssssssssssssssssssssssssssss"/> <bean:write name="empId"/> </body> </html:html> bean:resource标签true: <%@ page language="java" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %> <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:html lang="true"> <head> <html:base /> <title>header.jsp</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <bean:define id="empId" value="ssssssssssssssssssssssssssssss"/> <bean:write name="empId"/> </body> </html:html> bean:resource标签false: bean:include标签: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="zh-CN"> <head> <base href="http://localhost:8090/SS1/header.jsp"> <title>header.jsp</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> ssssssssssssssssssssssssssssss </body> </html> bean:include标签true: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="zh-CN"> <head> <base href="http://localhost:8090/SS1/header.jsp"> <title>header.jsp</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> ssssssssssssssssssssssssssssss </body> </html> bean:include标签false: ssssssssssssssssssssssssssssss