Struts标签(1)Logic标签
2008-12-20 13:20
281 查看
Struts标签(1)Logic标签
1.判断在指定范围内是否有指定的属性存在
2.判断指定属性的值是否相等
3.简单地进行各种类型的判断
4.迭代标签,使用相当广泛!!!要重点掌握!
5. Set迭代输出,其中的元素无序
6.通过迭代标签可以方便地输出Map集合中的数据
7. 双层迭代标签
1.判断在指定范围内是否有指定的属性存在
<%@ 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> <html:base /> <title>LogicDemo01.jsp</title> </head> <body> <% request.setAttribute("uname","yyg"); session.setAttribute("password","juke"); // 通过标签判断在指定范围内是否有指定的属性存在 %> <!-- scope也可以不写(没有指定作用域),那样就默认在整个范围(从页到整个程序)内进行搜索 --> <logic:present name="uname" scope="request"> <h1>指定的属性存在,内容为:${uname}</h1> </logic:present> <logic:notPresent name="name" scope="request"> <h1>指定的属性不存在!!!</h1> </logic:notPresent> <logic:present name="password" scope="session"> <h1>指定的属性存在,内容为:${password}</h1> </logic:present> <logic:notPresent name="pass" scope="session"> <h1>指定的属性不存在!!!</h1> </logic:notPresent> </body> </html:html> |
指定的属性存在,内容为:yyg指定的属性不存在!!!指定的属性存在,内容为:juke指定的属性不存在!!! |
<%@ 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> <html:base /> <title>LogicDemo02.jsp</title> </head> <body> <% request.setAttribute("uname","yyg"); // 通过标签判断指定属性的值是否相等 %> <logic:equal name="uname" value="yyg" scope="request"> <h1>语句满足条件,内容是:${uname}</h1> </logic:equal> <logic:notEqual name="password" value="yyg" scope="request"> <h1>语句不满足条件!!!</h1> </logic:notEqual> </body> </html:html> |
语句满足条件,内容是:yyg语句不满足条件!!! |
<%@ 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> <html:base /> <title>LogicDemo03.jsp</title> </head> <body> <% //request.setAttribute("ref",new Integer(1)); request.setAttribute("ref",new Character('1')); // 比较实体与常数的大小 // 使用此种逻辑标签最大的好处是可以简单地进行各种类型的判断 %> <logic:equal name="ref" scope="request" value="1"> <h1>值等于1!!!</h1> </logic:equal> <logic:notEqual name="ref" scope="request" value="0"> <h1>值不等于0!!!</h1> </logic:notEqual> <logic:greaterThan name="ref" scope="request" value="0"> <h1>值大于0!!!</h1> </logic:greaterThan> <logic:greaterEqual name="ref" scope="request" value="0"> <h1>值大于等于0!!!</h1> </logic:greaterEqual> <logic:lessThan name="ref" scope="request" value="2"> <h1>值小于2!!!</h1> </logic:lessThan> <logic:lessEqual name="ref" scope="request" value="2"> <h1>值小于等于2!!!</h1> </logic:lessEqual> </body> </html:html> |
值等于1!!!值不等于0!!!值大于0!!!值大于等于0!!!值小于2!!!值小于等于2!!! |
<%@ 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>LogicDemo04.jsp</title> </head> <body> <% List all = new ArrayList(); all.add("yyg"); all.add("juke"); all.add("com.ws.jpo"); all.add("www.sohu.com"); // 将对象保存在属性之中 request.setAttribute("list",all); // 迭代标签,使用相当广泛!!!要重点掌握! %> <logic:iterate id="str" name="list" scope="request"> <h2>${str}</h2> <h1><%=str%></h1> </logic:iterate> </body> </html:html> |
yygyygjukejukecom.ws.jpocom.ws.jpowww.sohu.comwww.sohu.com |
<%@ 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> <html:base /> <title>LogicDemo05.jsp</title> </head> <body> <% Set set = new TreeSet(); set.add("China"); set.add("Japan"); set.add("America"); request.setAttribute("country",set); // Set,其中的元素无序 %> <logic:iterate id="cou" name="country" scope="request"> <h1>${cou}</h1> </logic:iterate> </body> </html:html> |
AmericaChinaJapan |
<%@ 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" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:html lang="true"> <head> <html:base /> <title>LogicDemo06.jsp</title> </head> <body> <% Map map = new HashMap(); map.put("name","yyg"); map.put("password","juke"); request.setAttribute("m",map); // 回顾:Map集合本身不直接支持迭代输出,输出步骤:Map-->Set-->Iterator-->Map.Entry-->key、value // 通过迭代标签可以方便地输出Map集合中的数据 %> <logic:iterate id="str" name="m" scope="request"> <h1>${str.key}-->${str.value}</h1> </logic:iterate> </body> </html:html> |
password-->jukename-->yyg |
<%@ 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> <html:base /> <title>LogicDemo07.jsp</title> </head> <body> <% // 在Map中保存多个Collection集合,该如何进行输出呢? Map m = new HashMap(); List list = new ArrayList(); Set set = new HashSet(); list.add("yyg"); list.add("juke"); m.put("li",list); set.add("ws"); set.add("jpo"); m.put("se",set); // 在一个map中保存了多个集合,每个集合又包含多个内容 // 双层迭代标签 request.setAttribute("map",m); %> <logic:iterate id="str" name="map" scope="request"> <h1>${str.key}--><br> <!-- name="str":str是内层迭代的bean; scope="page":作用域就在当前页面(map从request中拿,而str就从当前页面拿); property="value":取得的值是str.value --> <logic:iterate id="tempstr" name="str" scope="page" property="value"> <li>${tempstr} </logic:iterate> </h1> </logic:iterate> </body> </html:html> |
li-->· yyg· jukese-->· ws· jpo |
相关文章推荐
- 使用Struts中logic:iterate标签的问题
- Struts - 标签库(Logic)
- Struts的logic标签使用注意事项(随时补充)
- struts标签logic
- Struts源码研究 - logic-Iterator标签篇
- Struts标签---logic:Iterate使用方法
- Struts之LOGIC标签库详解
- struts标签:logic标签
- Struts源码研究 - logic-Iterator标签篇
- Struts源码研究 - logic-Iterator标签篇[转载]
- Struts标签中的多层logic:iterator详解(原创)
- Struts的logic标签
- Struts 1.x | <logic> 标签库
- struts logic标签学习笔记
- struts标签logic:iterate学习
- struts的LOGIC标签详解
- struts标签--logic总结
- struts的LOGIC标签详解
- Struts的logic标签(转)
- Struts中Logic逻辑标签的作用及用法