via: http://blog.csdn.net/chinajust/article/details/3922718
1:struts2 标签库的定义在**-core-版本号.jar META-INF 路径下找到struts-tags.tld文件;使用该标签需要在web 项目里面导入标签库:
A:在web.xml文件 (默认 可以省略)
<taglib>
<taglib-uri>/struts-tags</taglib-uri>
<taglib-location>/WEB-INF/lib/*.jar</taglib-location>
<taglib>
B:在jsp 导入标签的定义
<%@ taglib prefix="s" uri="/struts-tags"%>
注意uri要一直,上面定义的是默认写法
2:OGNL struts2 利用了内建的ognl表达式,它基于XWork,增加了对ValueStack的支持 ,在jsp里面通过ognl访问属性,struts2会自动搜寻栈内的所有实体。直到找到位置。
如:#person.address.ip 等于 person.getAddress().getIp();翻译结果为条用get方法 或是jstl的${person.address.ip}
<s:if>用法
A:直接写表达式
<s:set name='china' value='china'>
<s:if test="${china=='china'}">show</s:if>
result: show
<s:set name="count" value="99">
<s:if test="${count>0}">bigger than 0</s:if>
<s:else>not</s:else>
result: bigger than 0
B:在遍历里面使用判断:
<s:iterator id="id" value="label">
<s:if test="%{#id.attrValueId!=0}">
<s:property value="#id.attrValue" />
<s:property value="#id.countAll" /> <s:property value="#id.countRequest" />
</s:if>
<s:else>
<s:property value="#id.attrValue" />
</s:else>
</s:iterator>
label是一个List<Attribu> Attribu 包含属性attrValueId和countAll 在s:iterator域内这是id的值是"id",使用ognl读取遍历对象的方法是 #id test="%{#id.attrValueId!=0}" 看子对象的属性attrValueId是否为0
<s:property value="#id.attrValue" /> 打印子对象的attrValue属性
C:直接读取对象
<s:if test="request.price==null||request.price<=0">
</s:if>
读取对象request,判断price是否小于0; request 可以是如何的javaBean,也可以是基本属性
D:直接读取对象的另一种写法
<s:if test="%{aTransactionSummaryBean!=null}">
E:多个条件的判断
<s:if test='%{isShowAll=="Y"||isShowAll==null||isShowAll==""}'>
<li class="selected">
</s:if>
<s:else>
<li>else
</s:else>
isShowAll 为Action 里面的字符串属性
F:直接拿Action里面的boolean 貌似不xing
Action里面
private boolean choosed = true;
public boolean isChoosed(){
return choosed;
}
<s:if test="choosed"></s:if>
发现这个判断无法正确运行,也许是ognl 是通过get方法来获取对象的,如果在action 里面有下面的方法;
public String getChoosed(){
return "true";
}
上面那个s:if可以正确执行
最后注意一点:ognl和jstl标签不能互相嵌套
相关推荐
struts2 <s:if>标签使用struts2 <s:if>标签使用struts2 <s:if>标签使用struts2 <s:if>标签使用struts2 <s:if>标签使用struts2 <s:if>标签使用
taskInstanceId=<s:property value="id"/>" >我来处理)</s:if> <s:elseif test='{#taskName == "受评对象准备评级资料"}'> ${pageContext.request.contextPath}/ga/needModify.action?taskInstanceId=<s:...
<s:if> 在进行字符创和字符比较时,会忽略一些细节,对于对该控件不是经常使用的,需要注意与字符和字符串的比较的区别
<%@ taglib uri="/struts-tags" prefix="s" %> 结合例子,重点掌握以下标签的用法 (1) <s:property> (2) <s:set> (3) <s:if> 、<s:elseif>、<s:else> (4) <s:iterator> (5) <s:include> (6) <s:form>、<s:hidden> (7...
这是一份关于struts2标签库的文档。 <%@ taglib prefix="s" uri="/struts-tags"%> ...<s:if test="#request.username=='hzd'">欢迎hzd</s:if> <s:elseif>:同上。 <s:else> …… …… 很实用的,就是简洁明了
<%@ taglib uri="/struts-tags" prefix="s" %> 结合例子,重点掌握以下标签的用法 (1) <s:property> (2) <s:set> (3) <s:if> 、<s:elseif>、<s:else> (4) <s:iterator> (5) <s:include> (6) <s:form>、<s:hidden> (7...
<%@ taglib prefix="s" uri="/struts-tags" %> 就能使用struts2.0的标签库 下面就介绍每个标签的具体应用实例说明:按字母排列 A: 1. 2. <s:a href=""></s:a>-----超链接,类似于html里的<a></a> 3. <s:...
<s:if test="page.hasPre"><a href="list-users?page.pageNow=<s:property value="page.pageNow-1"/>">上一页</a></s:if> <s:if test="page.hasNext"><a href="list-users?page.pageNow=<s:property value="page....
主要介绍Strus2中的通用标签,主要有<s:url>, <s:set>, <s:push>, <s:if>, <s:elseif>, <s:else>, <s:iterator>, <s:sort>, <s:date>, <s:a>等几个标签的具体用法,希望能对大家有帮助。
2.1 B/S和C/S系统区别 31 2.2 JSP和Servlet介绍 32 2.3 XML知识介绍 34 第3章 Struts2核心技术 37 3.1 使用web.xml配置Struts2实现Web项目Struts2应用 37 3.2 使用配置文件struts.xml实现页面导航定义 38 3.3 使用...
Struts的一些标签,如checkboxlist、s:if---s:else等
Preface Over the last few... If you are building applications, web-based or not, one of the main things you will learn from this book is that frameworks such as Struts are a great time investment.
15.3.1 使用s:token/表单标签 313 15.3.2 令牌拦截器规则的例外 314 15.4 自动显示等待页面 316 15.5 完成CRUD操作的一个动作 317 15.5.1 CRUD 317 15.5.2 拦截器和接口 318 15.5.3 连接各部分 323 15.6 Tiles和...
struts1.3.9 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the ...
1.2.4 struts.xml 配置文件......................................................................................7 2 Action 研究.............................................................................
So I was sold on Struts 2 by the time Manning contacted me later that year to see if I was interested in teaming up with Don Brown to write a Struts 2 book for their In Action series. I was looking ...
这是一个典型的分支控制指令,该指令的作用完全类似于Java语言中的if,if指令的语法格式如下: <#if condition>... <#elseif condition>... <#elseif condition>... <#else> ... </#if> 例子如下: <#if (age>...
Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross...
Even if you never implement a system with Struts, you may get some ideas for your future servlets and JSP page implementation. Introduction Kids in grade school put ...
jsp自定义标签,比如说if,foreach,out,format