Struts标签(2)Bean标签
来源:互联网 发布:java 超时异常 编辑:程序博客网 时间:2024/05/16 11:21
<bean:write>标签(重点掌握)
1. <bean:define>标签
<%@ page language="java" pageEncoding="gbk"%>
<%@ 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>BeanDemo01.jsp</title>
</head>
<body>
<!--bean:define标记可以定义新bean,可以复制现有bean,也可以从现有bean复制属性-->
<bean:define id="str" value="Hello JPO!!!"></bean:define>
<h1><bean:write name="str"></bean:write></h1>
<h1>${str}</h1>
</body>
</html:html>
Hello JPO!!!
Hello JPO!!!
2. <bean:size>标签
<%@ page language="java" pageEncoding="gbk"%>
<%@ page import="java.util.*" %>
<%@ 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>BeanDemo02.jsp</title>
</head>
<body>
<%
Map m = new HashMap();
m.put("one","1");
m.put("two","2");
m.put("three","3");
m.put("zero","0");
request.setAttribute("map",m);
Collection c = new ArrayList();
c.add("ws");
c.add("jpo");
c.add("jp3");
request.setAttribute("namecol",c);
%>
<!-- bean:size标签,求出长度:数组、Collection、Map -->
<bean:size id="size" name="map" scope="request"/>
<h1>Map长度是:${size}</h1>
<bean:size id="si" name="namecol" scope="request"/>
<h1>Collection长度是:${si}</h1>
</body>
</html:html>
Map长度是:4
Collection长度是:3
3. <bean:write>标签(重点掌握)
<%@ page language="java" pageEncoding="gbk"%>
<%@ page import="org.ws.tag.*" %>
<%@ 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>BeanDemo04.jsp</title>
</head>
<body>
<!-- 推荐写法(使用标签) -->
<jsp:useBean id="simple" class="org.ws.tag.SimpleBean" scope="request"></jsp:useBean>
<jsp:setProperty name="simple" property="name" value="ws"/>
<jsp:setProperty name="simple" property="password" value="jpo"/>
<h1>使用JSP标签</h1>
名称:<jsp:getProperty name="simple" property="name"/>
密码:<jsp:getProperty name="simple" property="password"/>
<!-- bean:write标签 -->
<h1>使用bean标签</h1>
名称:<bean:write name="simple" property="name" scope="request"/>
密码:<bean:write name="simple" property="password" scope="request"/>
<!-- JSP2.0的表达式语言EL(Expression Language) -->
<!-- 在JSP2.0中,可以使用EL代替Struts中的bean:write标签 -->
<h1>使用EL</h1>
名称:${simple.name}
密码:${simple.password}
</body>
</html:html>
上面的推荐写法(使用标签),效果等同于下面的这段Java代码:
<%
SimpleBean si = new SimpleBean();
si.setName("yyg");
si.setPassword("juke");
request.setAttribute("simple",si);
%>
SimpleBean.java
package org.ws.tag;
public class SimpleBean {
private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
使用JSP标签
名称:ws 密码:jpo
使用bean标签
名称:ws 密码:jpo
使用EL
名称:ws 密码:jpo
4. <bean:message>标签
<%@ page language="java" pageEncoding="gbk"%>
<%@ 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>BeanDemo05.jsp</title>
</head>
<body>
<!-- Struts国际化:根据浏览器的不同,自动进行语言的显示,自动去调用相应的属性文件 -->
<!-- 在bean:message标签中提供了一个占位功能,在输出的文件中占着一位,这一位的数据等着标签来填写 -->
<bean:message key="welcome" arg0="WS"/>
</body>
</html:html>
ApplicationResources.properties
# Resources for parameter 'com.ws.struts.ApplicationResources'
# Project StrutsTag
welcome={0}, You are welcome!!!
WS, You are welcome!!!
- Struts标签(2)Bean标签
- struts标签:bean标签
- Struts标签-BEAN标签
- struts标签---bean标签
- Struts 2 Bean 标签教程
- struts标签:bean标签(转贴)
- Struts - 标签库(Bean)
- struts Bean标签库
- struts标签-------bean
- Struts-Bean 标签库
- struts Bean 标签库
- Struts-Bean 标签库
- Struts 标签-bean
- struts bean 标签
- Struts-bean标签库
- struts标签--bean:define
- Struts bean 标签介绍
- Struts Bean标签
- .NET面试题
- Kruskal 最小生成树的总结
- 发现自己离不开编程了。
- program
- 小念头最高境界/梁 挺
- Struts标签(2)Bean标签
- 【转帖】【献给那些还不懂爱的人】纪念我的母亲
- 汉字的拼音首字母[支持Unicode]
- gcc汇编
- JAVA相关基础知识总结(连载)-8
- I300上网设置方法
- JAVA相关基础知识总结(连载)-9
- JAVA相关基础知识总结(连载)-10
- JAVA相关基础知识总结(连载)-11