`
summer_021
  • 浏览: 55311 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

Struts1_学习笔记3_struts0300_taglib_bean_logic_Iterate标签

 
阅读更多
bean标签:

Action:
public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// 普通属性
		request.setAttribute("hello", "Hello World");
		// html文本
		request.setAttribute("hz", "<font color='red'>杭州欢迎您</font>");
		// 日期
		request.setAttribute("today", new Date());
		// 数字
		request.setAttribute("n", 123456.987);
		// 结构
		Group group = new Group();
		group.setName("和盈");
		User user = new User();
		user.setUsername("张三");
		user.setAge(18);
		user.setGroup(group);
		request.setAttribute("user", user);

		return mapping.findForward("success");
	}



页面显示:

<h1>测试BeanWrite</h1>
	<hr>
	<li>普通字符串</li><br>
	hello(jsp脚本):<%=request.getAttribute("hello") %><br>
	hello(标签):<bean:write name="hello"/><br>
	<p>
	<li>html文本</li><br>
	hz(default):<bean:write name="hz"/><br>
	hz(filter="true"):<bean:write name="hz" filter="true"/><br>
	hz(filter="false"):<bean:write name="hz" filter="false"/><br>
	<p>
	<li>格式化日期</li><br>
	today(default):<bean:write name="today"/><br>
	today(format="yyyy-MM-dd HH:mm:ss"):<bean:write name="today" format="yyyy-MM-dd HH:mm:ss"/>
	<p>
	<li>格式化数字</li><br>
	n(default):<bean:write name="n"/><br>
	n(format="###,###.####"):<bean:write name="n" format="###,###.####"/><br>
	n(format="###,###.####"):<bean:write name="n" format="###,###.0000"/><br>
	<p>
	<li>结构</li><br>
	姓名:<input type="text" value="<bean:write name="user" property="username"/>"><br>
	年龄:<input type="text" value="<bean:write name="user" property="age"/>"><br>
	所属组:<input type="text" value="<bean:write name="user" property="group.name"/>"><br>
	</body>


配置文件:
<action-mappings>
		<action path="/beanwrite" type="com.aowin.struts.BeanWriteTestAction">
			<forward name="success" path="/beanwrite.jsp" />
		</action>

		<action path="/emptypresent" type="com.aowin.struts.EmptyPresentTestAction">
			<forward name="success" path="/emptypresent.jsp" />
		</action>

		<action path="/iterate" type="com.aowin.struts.IterateTestAction">
			<forward name="success" path="/iterate.jsp" />
		</action>
	</action-mappings>

	<message-resources parameter="MessageResources" />


使用struts1 bean:write标签必须提供一份国际化文件: MessageResources
否则会报:
Cannot find message resources under key org.apache.struts.action.MESSAGE
在src下面提供一份文件即可 内容为空也可以


使用bean标签需要在页面中加入:
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>   




logic标签:
Action:
@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		request.setAttribute("attr1", null);
		request.setAttribute("attr2", "");
		request.setAttribute("attr3", new ArrayList());
		return mapping.findForward("success");
	}


页面使用标签:
<h1>测试empty,notEmpty,present,notPresent</h1>
	<hr>
	<logic:empty name="attr1">
		attr1为空<br>
	</logic:empty>
	<logic:notEmpty name="attr1">
		attr1不为空<br>
	</logic:notEmpty>
	<logic:present name="attr1">
		attr1存在<br>
	</logic:present>
	<logic:notPresent name="attr1">
		attr1不存在<br>
	</logic:notPresent>
	
	<p>
	<logic:empty name="attr2">
		attr2为空<br>
	</logic:empty>
	<logic:notEmpty name="attr2">
		attr2不为空<br>
	</logic:notEmpty>
	<logic:present name="attr2">
		attr2存在<br>
	</logic:present>
	<logic:notPresent name="attr2">
		attr2不存在<br>
	</logic:notPresent>
	
	<p>
	<logic:empty name="attr3">
		attr3为空<br>
	</logic:empty>
	<logic:notEmpty name="attr3">
		attr3不为空<br>
	</logic:notEmpty>
	<logic:present name="attr3">
		attr3存在<br>
	</logic:present>
	<logic:notPresent name="attr3">
		attr3不存在<br>
	</logic:notPresent>



Iterate标签:

public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Group group = new Group();
		group.setName("和盈");
		
		List userList = new ArrayList();
		for (int i=0; i<10; i++) {
			User user = new User();
			user.setUsername("user_" + i);
			user.setAge(18+i);
			user.setGroup(group);
			userList.add(user);
		}
		
		request.setAttribute("userlist", userList);
		
		return mapping.findForward("success");
	}



页面显示:
<h1>测试Iterate</h1>
	<hr>
	<li>jsp脚本</li><br>
	<table border="1">  
		<tr>
			<td>姓名</td>
			<td>年龄</td>
			<td>所属组</td>
		</tr>
		<%
			List userList = (List)request.getAttribute("userlist");
			if (userList == null || userList.size() == 0) {
		%>
			<tr>
				<td colspan="3">没有符合条件的数据!</td>
			</tr>
		<%
			}else {
				for (Iterator iter=userList.iterator(); iter.hasNext(); ) {
					User user = (User)iter.next();
		%>
			<tr>
				<td><%=user.getUsername() %></td>
				<td><%=user.getAge() %></td>
				<td><%=user.getGroup().getName() %></td>
			</tr>
		<%
				}
			}
		%>
	</table>
	
	<p>
	<li>标签</li><br>
	<table border="1">
		<tr>
			<td>姓名</td>
			<td>年龄</td>
			<td>所属组</td>
		</tr>
		<logic:empty name="userlist">
			<tr>
				<td colspan="3">没有符合条件的数据!</td>
			</tr>
		</logic:empty>
		<logic:notEmpty name="userlist">
			<logic:iterate id="u" name="userlist">
				<tr>
					<td>
						<bean:write name="u" property="username"/>
					</td>
					<td>
						<bean:write name="u" property="age"/>
					</td>
					<td>
						<bean:write name="u" property="group.name"/>
					</td>
				</tr>
			</logic:iterate>
		</logic:notEmpty>
	</table>	


使用Iterate标签加上:
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>    
<%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic"%>  
分享到:
评论

相关推荐

    Struts 2.1.8_学习源码

    Struts2_03Taglib : Struts2常用标签的使用方法 Struts2默认支持OGNL、JSTL、Groovy和Velcity表达式 Struts2_04ActionResultType : Struts2关于Action跳转类型的应用 对各种不同的跳转类型使用的实例 Struts2_05...

    struts 标签 logic:iterate使用 logic:iterate

    我就是靠这个文档实现logic:iterate的循环的 struts 标签 logic:iterate使用 logic:iterate &lt;br&gt;第一页 是struts官方的说明, 第二页 是个例子 第三页 是我实现的arrayList放入标签的方法。 这是页面...

    Struts1.3 备忘笔记

    03 Struts_03Taglib : 演示Struct的标签库,html、bean、logic标签的用法 04 Struts_04DispatchAction : 分发Action,根据设置的参数值提交到不同的方法进行处理业务,演示数学运算 05 Struts_05DynaActionForm : 相...

    解决MyEclipse下开发Struts异常:org.apache.struts.taglib.bean.CookieTei.doc 下载

    绝对可以解决这个这个问题。Struts初学者绝对可以受用的方法。

    struts2.0 taglib 标签库

    struts2.0 taglib struts2.0 标签库,总结了从的全部

    struts taglib使用示例

    struts taglib使用示例 struts taglib使用示例 struts taglib使用示例struts taglib使用示例 struts taglib使用示例

    taglib(struts2标签).doc

    taglib(struts2标签).doc

    struts-taglib-1.3.10.jar struts-taglib.jar taglib.jar

    struts-taglib-1.3.10.jar struts-taglib.jar taglib.jar

    struts-taglib-1.3.8.jar

    struts-taglib-1.3.8.jar struts-taglib-1.3.8.jar

    struts2标签库

    用过struts1.x的人都知道,标签库有html、bean、logic、tiles, 而struts2.0里的标签却没有分类,只用在jsp头文件加上 &lt;%@ taglib prefix="s" uri="/struts-tags" %&gt; 就能使用struts2.0的标签库

    pager-taglib_struts2 安装使用

    pager-taglib 安装包和使用手册。

    struts2 标签库 帮助文档

    &lt;%@ taglib prefix="s" uri="/struts-tags" %&gt; 就能使用struts2.0的标签库 下面就介绍每个标签的具体应用实例说明:按字母排列 A: 1. 2. &lt;s:a href=""&gt;&lt;/s:a&gt;-----超链接,类似于html里的&lt;a&gt;&lt;/a&gt; 3. ...

    struts2标签库例子

    主要介绍了struts2的标签的详细使用例子说明

    Struts Taglib

    关于Struts Taglib的现实介绍

    jsp使用自定义标签taglib分页系列——完整例子

    jsp使用自定义标签taglib分页系列——完整例子(其中struts控件和包我没有加入,需要自己加入)

    struts2自定义标签案例详解

    Struts2中实现自定义标签很简单,主要分为3步: 1.创建taglib文件(.tld),编写标签声明。 2.编写自定义标签类。 3.在页面中使用标签。 下面以一个自定义的分页标签为例,进行说明。 其实,开发自定义标签并不...

    struts2.0的标签学习资料

    用过struts1.x的人都知道,标签库有html、bean、logic、tiles, 而struts2.0里的标签却没有分类,只用在jsp头文件加上 &lt;%@ taglib prefix="s" uri="/struts-tags" %&gt; 就能使用struts2.0的标签库

    struts标签中文文档

    struts标签中文文档 下载附件后把taglib1.war放在tomcat的webapps下,(或用其他应用服务器) 然后启动tomcat服务 在浏览器中输入http://localhost:8080/taglib1即可

    struts2 标签

    struts2 标签 Taglib (Struts2标签库)

Global site tag (gtag.js) - Google Analytics