`
啸笑天
  • 浏览: 3443179 次
  • 性别: Icon_minigender_1
  • 来自: China
社区版块
存档分类
最新评论

bean:resource bean:include jsp:include

阅读更多

bean:include

一。用于执行对页面的请求,并将响应结果的客户端代码存储在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到本地处理。

 

bean:resource

用于加载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

 

 

 

分享到:
评论

相关推荐

    李兴华 Java Web 开发实战经典_带源码_高清pdf 带书签 上

    16.2.6、&lt;bean:resource&gt;标签 16.2.7、国际化与&lt;bean:message&gt;标签 16.3、Logic标签 16.3.1、&lt;logic:present&gt;标签和&lt;logic:notPresent&gt;标签 16.3.2、&lt;logic:empty&gt;标签和&lt;logic:notEmpty&gt;标签 16.3.3、关系运算...

    MLDN+李兴华+Java+Web开发实战经典.part3.rar )

    16.2.6、&lt;bean:resource&gt;标签 16.2.7、国际化与&lt;bean:message&gt;标签 16.3、Logic标签 16.3.1、&lt;logic:present&gt;标签和&lt;logic:notPresent&gt;标签 16.3.2、&lt;logic:empty&gt;标签和&lt;logic:notEmpty&gt;标签 16.3.3、...

    李兴华 java_web开发实战经典 源码 完整版收集共享

    16.2.6、&lt;bean:resource&gt;标签 16.2.7、国际化与&lt;bean:message&gt;标签 16.3、Logic标签 16.3.1、&lt;logic:present&gt;标签和&lt;logic:notPresent&gt;标签 16.3.2、&lt;logic:empty&gt;标签和&lt;logic:notEmpty&gt;标签 16.3.3、关系运算...

    李兴华 Java Web 开发实战经典_带源码_高清pdf 带书签 下

    16.2.6、&lt;bean:resource&gt;标签 16.2.7、国际化与&lt;bean:message&gt;标签 16.3、Logic标签 16.3.1、&lt;logic:present&gt;标签和&lt;logic:notPresent&gt;标签 16.3.2、&lt;logic:empty&gt;标签和&lt;logic:notEmpty&gt;标签 16.3.3、关系运算...

    李兴华 Java Web 开发实战经典 高清扫描版Part3

    16.2.6、&lt;bean:resource&gt;标签 16.2.7、国际化与&lt;bean:message&gt;标签 16.3、Logic标签 16.3.1、&lt;logic:present&gt;标签和&lt;logic:notPresent&gt;标签 16.3.2、&lt;logic:empty&gt;标签和&lt;logic:notEmpty&gt;标签 16.3.3、关系运算...

    李兴华Java Web开发实战经典.pdf (高清版) Part1

    16.2.6、&lt;bean:resource&gt;标签 16.2.7、国际化与&lt;bean:message&gt;标签 16.3、Logic标签 16.3.1、&lt;logic:present&gt;标签和&lt;logic:notPresent&gt;标签 16.3.2、&lt;logic:empty&gt;标签和&lt;logic:notEmpty&gt;标签 16.3.3、...

    java web 视频、电子书、源码(李兴华老师出版)

    16.2.6、&lt;bean:resource&gt;标签 16.2.7、国际化与&lt;bean:message&gt;标签 16.3、Logic标签 16.3.1、&lt;logic:present&gt;标签和&lt;logic:notPresent&gt;标签 16.3.2、&lt;logic:empty&gt;标签和&lt;logic:notEmpty&gt;标签 16.3.3、...

    李兴华Java Web开发实战经典(高清版) Part2

    16.2.6、&lt;bean:resource&gt;标签 16.2.7、国际化与&lt;bean:message&gt;标签 16.3、Logic标签 16.3.1、&lt;logic:present&gt;标签和&lt;logic:notPresent&gt;标签 16.3.2、&lt;logic:empty&gt;标签和&lt;logic:notEmpty&gt;标签 16.3.3、...

    spring3.2+strut2+hibernate4

    spring3.2+strut2+hibernate4 注解方式。 spring.xml ... &lt;description&gt;Spring公共配置文件 ...-- &lt;bean id="sessionFactory"--&gt; ...-- class="org.springframework.... &lt;include file="/resource/struts-user.xml"&gt;&lt;/include&gt;

    SpringMVC-Mybatis-Shiro-redis-master 权限集成缓存中实例

    解决方案:在 FreeMarkerViewExtend.java 33行处 增加了BasePath ,通过BasePath 来控制请求目录,在 Freemarker 中可以自由使用,而 JSP 中是直接在 JSP 中获取BasePath 使用。 解决后遗症:因为我们的权限是通过...

    cms后台管理

    env.include(TPL_STYLE_LIST + listStyle + TPL_SUFFIX, UTF8, true); } else if (InvokeType.userDefined == type) { if (StringUtils.isBlank(listStyle)) { throw new ParamsRequiredException(PARAM_STYLE_...

    J2EE应用开发详解

    67 5.2 JSP页面的结构 68 5.3 脚本元素 68 5.3.1 Scriptlet元素 69 5.3.2 Expression元素 69 5.3.3 Declaration元素 70 5.4 指令 73 5.4.1 page指令 73 5.4.2 include指令 75 5.5 动作 76 5.5.1 Resource动作 ...

Global site tag (gtag.js) - Google Analytics