struts2标签
一、通用标签
1、property
Name |
Required |
Default |
Evaluated |
Type |
Description |
|---|---|---|---|---|---|
| default | false | false | String | The default value to be used if value attribute is null | |
| escape | false | true | false | Boolean | Deprecated. Use 'escapeHtml'. Whether to escape HTML |
| escapeCsv | false | false | false | Boolean | Whether to escape CSV (useful to escape a value for a column) |
| escapeHtml | false | true | false | Boolean | Whether to escape HTML |
| escapeJavaScript | false | false | false | Boolean | Whether to escape Javascript |
| escapeXml | false | false | false | Boolean | Whether to escape XML |
| value | false | <top of stack> | false | Object | Value to be displayed |
<s:property value="username" />输出变量名为username的变量,value中的值会被当成ognl表达式输出
<s:property value="'username'" />输出username,加了单引号不会当成ognl表达式而是当成字符串输出
<s:property value="admin" default="xiaoming" /> 输出变量名为admin的值,如果没有则默认为xiaoming
<s:property value="'<br/>'" escape="false" />
2、set
Name |
Required |
Default |
Evaluated |
Type |
Description |
|---|---|---|---|---|---|
| id | false | false | String | Deprecated. Use 'var' instead | |
| name | false | false | String | Deprecated. Use 'var' instead | |
| scope | false | action | false | String | The scope in which to assign the variable. Can be application, session, request, page, or action. |
| value | false | false | String | The value that is assigned to the variable named name | |
| var | false | false | String | Name used to reference the value pushed into the Value Stack | |
<s:set var="username" value="xiaomi" />默认为request和ActionContext
从request取值<s:property value="#request.username" />(debug标签可能在username还未放到request中时就已经形成了,所以有时候会看不到)
从ActionContext取值<s:property value="#username" />
设定范围<s:set var="username" value="xiaomi" scope="session" />
从设定范围取值<s:property value="#session.username" />
3、bean
Name |
Required |
Default |
Evaluated |
Type |
Description |
|---|---|---|---|---|---|
| id | false | false | String | Deprecated. Use 'var' instead | |
| name | true | false | String | The class name of the bean to be instantiated (must respect JavaBean specification) | |
| var | false | false | String |
Name used to reference the value pushed into the Value Stack |
|
调用无参构造函数构造一个User类示例:xiaomi<s:bean name="cn.orlion.model.User var="xiaomi"></s:bean>
调用无参构造函数构造一个User类示例:dami,初始化name为dami
<s:bean name="cn.orlion.model.User var="dami">
<s:param name="name" value="'dami'"></s:param> 这里value中的值必须要用单引号引起来,不然会被当成ognl表达式!!!
</s:bean>
4、include
Name |
Required |
Default |
Evaluated |
Type |
Description |
|---|---|---|---|---|---|
| value | true | false | String | The jsp/servlet output to include | |
<s:include value="/index.jsp" />
<s:include value="/index.jsp">
<s:param name="param1">value1</s:param> (value会被当成字符串处理)
<s:param name="param2">value2</s:param>
</s:include>
包含动态文件:
<s:set name="url" value="'/index.jsp'" />
<s:include value="%{#url}" />
5、param
Name |
Required |
Default |
Evaluated |
Type |
Description |
|---|---|---|---|---|---|
| name | false | false | String | Name of Parameter to set | |
| suppressEmptyParameters | false | false | false | Boolean | Whether to suppress empty parameters |
| value | false | The value of evaluating provided name against stack | false | String | Value expression for Parameter to set |
可以:<s:param name="param1" value="value1" />这里value1会被当成ognl表达式
也可以:<s:param name="param1" />value1</s:param>这里value1会被当成字符串
6、debug
不多作介绍
二、控制标签
1、if elseif else
<s:if test="%{false}">
<p>1</p>
</s:if>
<s:elseif test="%{true}">
<p>2</p>
</s:elseif>
<s:else>
<p>3</p>
</s:else>
2、iterator
Name |
Required |
Default |
Evaluated |
Type |
Description |
|---|---|---|---|---|---|
| begin | false | 0 | false | Integer | if specified the iteration will start on that index |
| end | false | Size of the 'values' List or array, or 0 if 'step' is negative | false | Integer | if specified the iteration will end on that index(inclusive) |
| id | false | false | String | Deprecated. Use 'var' instead | |
| status | false | false | false | Boolean | If specified, an instanceof IteratorStatus will be pushed into stack upon each iteration |
| step | false | 1 | false | Integer | if specified the iteration index will be increased by this value on each iteration. It can be a negative value, in which case 'begin' must be greater than 'end' |
| value | false | false | String | the iteratable source to iterate over, else an the object itself will be put into a newly created List | |
| var | false | false | String | Name used to reference the value pushed into the Value Stack |
遍历集合:(输出123)
<s:iterator value="{1,2,3}">
<s:property/>
</s:iterator>
自定义变量:(输出ABC)从集合中迭代取出赋值给val
<s:iterator value="{'a', 'b' , 'c'}" var="val">
<s:property value="#val.toUpperCase()"/>
</s:iterator>
使用status:
<s:iterator value="{'a' , 'b' , 'c'}" status="status">
<s:property/>
遍历过的元素的总数<s:property value="#status.count" />
当前元素的索引<s:property value="#status.index" />
当前是偶数<s:property value="#status.even" />
当前是奇数<s:property value="#status.odd" />
是否是第一个元素<s:property value="#status.first" />
是否是最后一个元素<s:property value="#status.last" />
</s:iterator>
遍历map
<s:iterator value="#{1:'a' , 2:'b' , 3:'c'}">
<s:property value="key" /> | <s:property value="value" />
</s:iterator>
<s:iterator value="#{1:'a' , 2:'b' , 3:'c'}" var="val">
<s:property value="#val.key" /> | <s:property value="#val.value" />
</s:iterator>
3、subset
Name |
Required |
Default |
Evaluated |
Type |
Description |
|---|---|---|---|---|---|
| count | false | false | Integer | Indicate the number of entries to be in the resulting subset iterator | |
| decider | false | false | org.apache.struts2.util.SubsetIteratorFilter.Decider | Extension to plug-in a decider to determine if that particular entry is to be included in the resulting subset iterator | |
| id | false | false | String | Deprecated. Use 'var' instead | |
| source | false | false | String | Indicate the source of which the resulting subset iterator is to be derived base on | |
| start | false | false | Integer | Indicate the starting index (eg. first entry is 0) of entries in the source to be available as the first entry in the resulting subset iterator | |
| var | false | false | String | The name to store the resultant iterator into page context, if such name is supplied |
三、UI标签
1、theme
主题,默认为xhtml,可以设置为simple/css_html/ajax
struts.xml中<constant name="theme" value="simple" />
struts2标签的更多相关文章
- struts2<s:property />标签
struts2的<property />标签是输出标签 其value属性是指定输出的内容,如果value属性没有写出来,则默认输出对象栈栈顶的元素. 例如,我们在对象栈中添加一个Perso ...
- struts2 <s:property/>标签的使用--输出时间格式转换
转载地址http://hi.baidu.com/nonyi_com/blog/item/acf1b8d74b6cf63e07088bc4.html 最近在使用struts2的<s:propert ...
- [Struts2] <s:property>标签
调用类中的属性,通过get方法调用,而非其属性名调用. 比如A类中有属性a1,a1的get方法是getA1Method(); 相应Action类中的get方法是getA1Action(). 那么需要通 ...
- struts2使用jsp和<s:property>标签获取json格式的返回数据
struts2使用jsp和<s:property>标签获取json格式的返回数据 1.struts2的action中 return "success"; 2.指向的返回 ...
- struts2 s:if标签以及 #,%{},%{#}的使用方法
<s:if>判断字符串的问题: 1.判断单个字符:<s:if test="#session.user.username=='c'"> 这样是从session ...
- struts2 s:if标签以及 #,%{},%{#}的使用方法等在资料整理
<s:if>判断字符串的问题: 1.判断单个字符:<s:if test="#session.user.username=='c'"> 这样是从session ...
- Struts2的OGNL标签详解
一.Struts2可以将所有标签分成3类: UI标签:主要用于生成HTML元素的标签. 非UI标签:主要用于数据库访问,逻辑控制等标签. Ajax标签:用于Ajax支持的标签. 对于UI标签,则有可以 ...
- struts2.0 s标签_小小鸟_百度空间
struts2.0 s标签 1. Struts2页面开发中常用标签使用说明 1.1.往action里传值的使用方式: <input name="userName" type= ...
- struts2:数据标签
目录 数据标签1. a标签2. set标签3. push标签4. bean/param标签5. date标签6. include标签7. url标签8. property标签9. debug标签10. ...
- Struts2之数据标签(二)
Struts2之数据标签(一):http://blog.csdn.net/u012561176/article/details/46848817 1.action标签:使用此标签能够同意在JSP页面中 ...
随机推荐
- linux 第一题 计算题
#!/bin/bash echo "输入第一个数字" read A b= ]] do && [[ ${A} != *[!]* ]] then echo " ...
- poj 1737 Connected Graph
// poj 1737 Connected Graph // // 题目大意: // // 带标号的连通分量计数 // // 解题思路: // // 设f(n)为连通图的数量,g(n)为非连通图的数量 ...
- 小游戏runpig总结
前几天写了一个JavaScript小游戏,大概是这样的 demo:strongfanfan.top/RunPig 源代码:www.github.com/strongfanfan/RunPig 画风简 ...
- delphi 读写文本
将字符串写入txt文档,读取txt文档中的内容. //一次写字符串到文本文件,每次都会将原来的内容替换掉. procedure FilePutContents(f,s:String); // f为文件 ...
- *关于httl开源Java模板的使用心得
1.简介 HTTL (Hyper-Text Template Language) 是一个高性能的开源JAVA模板引擎, 适用于动态HTML页面输出, 可替代JSP页面, 指令和Velocity相似. ...
- Windows phone8.1教务在线客户端
本人是个大二学生,由于学校的教务在线一直没出windows phone的教务在线,而且本身也对wp开发感兴趣,所以就尝试着开发一下 由于没有系统的学习,只能在摸索中前进,这背后的原理很简单,可不容易实 ...
- 常用正则表达式-copy
匹配中文:[\u4e00-\u9fa5] 英文字母:[a-zA-Z] 数字:[0-9] 匹配中文,英文字母和数字及_: ^[\u4e00-\u9fa5_a-zA-Z0-9]+$ 同时判断输入长度:[\ ...
- c语言编译器(linux平台下安装c语言环境)一
gcc : 语言的默认编译器 (ubuntu下输入gcc,可根据终端输出查看是否安装了gcc) g++ : c++的默认编译器 (ubuntu下输入g++,可根据终端输出查看是否安装了g+ ...
- [.NET领域驱动设计实战系列]专题八:DDD案例:网上书店分布式消息队列和分布式缓存的实现
一.引言 在上一专题中,商家发货和用户确认收货功能引入了消息队列来实现的,引入消息队列的好处可以保证消息的顺序处理,并且具有良好的可扩展性.但是上一专题消息队列是基于内存中队列对象来实现,这样实现有一 ...
- 解决.NET Core中MailKit无法使用阿里云邮件推送服务的问题
在博问中(.net core怎么实现邮件发送)知道了MailKit无法使用阿里云邮件推送服务发送邮件的问题,自已实测也遇到同样的问题,而用自己搭建的邮件服务器没这个问题. 于是,向阿里云提交了工单.. ...