`

bean:define标签

阅读更多

<bean:define>标签用于定义一个变量.id属性指定变量的名字,toScope属性指定变量存放范围,如果没有设置toScope属性,则变量存放在page范围内.

给id属性定义变量赋值方式:

1.设置value属性,此时id属性定义的变量为字符串(String)类型,value属性代表这个变量的字符串值.

<bean:define id="str" value="Hello MLDN...."></bean:define>

可以通过jsp的EL语言${str}来取得或者><bean:write name="str"></bean:write>来取得值

2.同时设定name和property属性.name属性指定一个已经存在的bean,property属性指定已经存在的bean中的某个属性,id属性定义的变量值由property属性决定:

<%request.setAttribute("sessionBean",session);%>

<bean:define id="contextBean" name="sessionBean" property="servletContext"/>

Servlet Context name:<bean:write name="contextBean" property="servletContextName"/>

例:建立一个jsp页面:

 

<%@ page language="java" contentType="text/html;charset=gb2312"%>

<%@ 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" %>

<html:html lang="true">
<head>
<title>beanDefine.jsp</title>
</head>

<body>
<!-- bean:define作用
定义或复制一个对象
1.定义对象一般为String类型
2.复制对象->迭代标签 -->
<!-- 下面为定义一个对象 -->
<bean:define id="str" value="Hello MLDN...."></bean:define>
<!-- 两种输出方法
id就表示一个存放在四种属性范围之中的名称
name表示使用一个存放在四种属性范围中的对象-->
<h1>${str }</h1>
<!--bean:write 用于打印输出
使用对象时用name属性 -->
<h1><bean:write name="str"></bean:write></h1>
</body>
</html:html>

分享到:
评论

相关推荐

    struts1标签库

    bean:define 3 bean:header 4 bean:include 5 bean:message 5 bean:page 7 bean:parameter 7 bean:resource 8 bean:size 8 bean:struts 9 bean:write 9 html:base 10 html:cancel 11 html:select 12 ...

    logic:iterate标签当遍历的collection为Map时的使用

    1. Map里存放的是bean时 &lt;br&gt;&lt;logic:iterate id="destMap" name="srcMap"&gt; &lt;br&gt; &lt;bean:define id="bean" name="destMap" property="value" /&gt; &lt;br&gt; &lt;bean:write name="bean" property="name" /&gt; &lt;br&gt;...

    struts标签详解.chm

    &lt;bean:define id=”test” value=”this is a test”/&gt; 源bean在页作用域中被拷贝大哦请求作用域中的另一个bean: &lt;bean:define id=”targetBean” name=”sourceBean” scope=”page” toScope=”request”/&gt;

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

    16.3.5、重定向标签:&lt;logic:redirect&gt; 16.4、Html标签 16.4.1、&lt;html:form&gt;标签 16.4.2、&lt;html:text&gt;与&lt;html:password&gt;标签 16.4.3、&lt;html:radio&gt;标签 16.4.5、&lt;html:textarea&gt;标签 16.4.6、&lt;html:hidden...

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

    16.3.5、重定向标签:&lt;logic:redirect&gt; 16.4、Html标签 16.4.1、&lt;html:form&gt;标签 16.4.2、&lt;html:text&gt;与&lt;html:password&gt;标签 16.4.3、&lt;html:radio&gt;标签 16.4.5、&lt;html:textarea&gt;...

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

    16.3.5、重定向标签:&lt;logic:redirect&gt; 16.4、Html标签 16.4.1、&lt;html:form&gt;标签 16.4.2、&lt;html:text&gt;与&lt;html:password&gt;标签 16.4.3、&lt;html:radio&gt;标签 16.4.5、&lt;html:textarea&gt;...

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

    16.3.5、重定向标签:&lt;logic:redirect&gt; 16.4、Html标签 16.4.1、&lt;html:form&gt;标签 16.4.2、&lt;html:text&gt;与&lt;html:password&gt;标签 16.4.3、&lt;html:radio&gt;标签 16.4.5、&lt;html:textarea&gt;...

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

    16.3.5、重定向标签:&lt;logic:redirect&gt; 16.4、Html标签 16.4.1、&lt;html:form&gt;标签 16.4.2、&lt;html:text&gt;与&lt;html:password&gt;标签 16.4.3、&lt;html:radio&gt;标签 16.4.5、&lt;...

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

    16.3.5、重定向标签:&lt;logic:redirect&gt; 16.4、Html标签 16.4.1、&lt;html:form&gt;标签 16.4.2、&lt;html:text&gt;与&lt;html:password&gt;标签 16.4.3、&lt;html:radio&gt;标签 16.4.5、&lt;html:textarea&gt;...

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

    16.3.5、重定向标签:&lt;logic:redirect&gt; 16.4、Html标签 16.4.1、&lt;html:form&gt;标签 16.4.2、&lt;html:text&gt;与&lt;html:password&gt;标签 16.4.3、&lt;html:radio&gt;标签 16.4.5、&lt;html:textarea&gt;标签 16.4.6、&lt;html:hidden...

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

    16.3.5、重定向标签:&lt;logic:redirect&gt; 16.4、Html标签 16.4.1、&lt;html:form&gt;标签 16.4.2、&lt;html:text&gt;与&lt;html:password&gt;标签 16.4.3、&lt;html:radio&gt;标签 16.4.5、&lt;...

    JavaServer Faces 2.0完全参考手册(JSF2.0中文版) 1/2

    4.4.3 ui:define 4.4.4 ui:insert 4.4.5 ui:include 4.4.6 ui:param 4.5 facelets非模板化标签使用指南 4.5.1 ui:component 4.5.2 ui:fragment 4.5.3 ui:remove 4.5.4 ui:debug 第5章 托管bean与JSF表达式语言 5.1 ...

    JavaServer Faces 2.0完全参考手册(JSF2.0中文版).part1

    4.4.3 ui:define 4.4.4 ui:insert 4.4.5 ui:include 4.4.6 ui:param 4.5 facelets非模板化标签使用指南 4.5.1 ui:component 4.5.2 ui:fragment 4.5.3 ui:remove 4.5.4 ui:debug 第5章 托管bean与JSF表达式语言 5.1 ...

    play框架手册

    But you can define some interceptors in a totally different class, and link them with any controller using the @With annotation.由于java不允许多继承,通过控制器继承特点来应用拦截器就受到极大的限制。...

    play framework 框架手册 word 版

    But you can define some interceptors in a totally different class, and link them with any controller using the @With annotation.由于java不允许多继承,通过控制器继承特点来应用拦截器就受到极大的限制。...

Global site tag (gtag.js) - Google Analytics