近学习? Struts 2.1 Tags 做了些笔记,贴出来大家一起学习下,希望大家多多交流。
?
别的都不说了,我就贴代码,代码里注释比较详细,呵呵。
文件目录,如下:
?
?
?index.jsp 代码
- <%@?page?language="java"?import="java.util.*"?pageEncoding="UTF-8"%>??
- <%@page?import="com.rao.bean.Sex"%>??
- <%@?taglib?prefix="s"?uri="/struts-tags"%>??
- <%@?taglib?prefix="sx"?uri="/struts-dojo-tags"%>??
- <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN">??
- <html>??
- <head>??
- ??<title>My?page</title>??
- ??<s:head?theme="xhtml"/>??
- ??<sx:head?parseContent="true"/>??
- </head>??
- ??
- ??<body>??
- ????Struts?2.1?Tags??
- ????<br/>??
- ????<br/>??
- ????一、控制标签<br/><hr?size="3"?color="red">??
- ??????
- ?????#、if?/elseif/?else?@用于逻辑判断<br/>??
- ?????<s:set?name="bir"?value="-12"></s:set>??
- ?????<s:if?test="#bir>=180?||?#bir<0">??
- ????????你是何方妖怪???
- ?????</s:if>??
- ?????<s:elseif?test="#bir<=18?&&?#bir>=0">??
- ????????未成年人不能进入!??
- ?????</s:elseif>??
- ?????<s:elseif?test="#bir<=60?&&?#bir>=18">??
- ????????您已经成年!??
- ?????</s:elseif>??
- ?????<s:else>??
- ????????您已经老了!??
- ?????</s:else>??
- ?????<br/>--------------------------<br/>??
- ?????#、append?@用于将多个集合合并<br/>??
- ?????<s:set?name="appList1"?value="{'111','222','333','444'}"></s:set>??
- ?????<s:set?name="appList2"?value="{'aaa','bbb','ccc','ddd'}"></s:set>??
- ?????<s:append?var="newAppList">??
- ????????<s:param?value="appList1"></s:param>??
- ????????<s:param?value="appList2"></s:param>??
- ?????</s:append>??
- ?????<s:iterator?value="#newAppList">??
- ????????<s:property/>?|???
- ?????</s:iterator>??
- ??????<br/>--------------------------<br/>??
- ?????#、generator??<br/>??
- ?????generator 标签,该标签可以将指定字符串按指定分隔符分割成多个字串。生成的多个字串可以用iterator标签进行迭代输出。可以这么理解:generator标 签将一个字符串转换成一个List集合。在该标签体内,整个临时生成的集合将为Valuestack的顶端,但一旦该标签结束,生成的集合将被移除 Valuestack。generator标签有如下几个属性:??
- ????<br/>??
- ????1、count属性:指定生成集合中元素的总数。可选属性。<br/>??
- ??????
- ????2、val属性:必填属性,指定被解析的字符串。<br/>??
- ??????
- ????3、separator属性:这是一个必填属性,指定用于分割字符串的分隔符。<br/>??
- ??????
- ????4、 converter属性:可选属性,指定一个转换器,转换器负责将生成的集合中的每个字符串转换成对象,通过这个转换器可以将一个含有分隔符的字符串解析 成对象的集合。转换器必须一个继承org.apache.struts2.util.IteratorGenerator.Converter的对 象。??
- ????<br/>??
- ????5、var属性,可选属性。如果指定了该属性,则将生成的集合保存在Stack?Context中。如果不指定该属性,则将生成的集合放入ValueStack的顶端,该标签一结束,生成的集合就被移除。该属性也可替换成id。??
- ????<br/>??
- ?????<s:generator??val="'aaa,bbb,ccc,ddd'"??separator=","?count="2">??
- ????????<s:iterator>??
- ????????????<s:property/>??
- ????????</s:iterator>??
- ?????</s:generator><br/>??
- ??
- ??????<br/>--------------------------<br/>??
- ?????#、iterator?用于迭代数据<br/>??
- ?????<s:set?name="iterList"?value="{'aaa','bbb','ccc','ddd'}"></s:set>??
- ?????<table?border="1">??
- ?????<tr>?????
- ????????????????<td>???索引???</td>?????
- ????????????????<td>???值???</td>?????
- ????????????????<td>???奇????</td>?????
- ????????????????<td>???偶?????</td>?????
- ????????????????<td>???首?????</td>?????
- ????????????????<td>???尾?????</td>?????
- ????????????????<td>??当前迭代数量????</td>?????
- ????????????</tr>?????
- ???????
- ????????<s:iterator?value="{'aaa','bbb','ccc','ddd','eee','fff'}"?begin="1"?status="s">??
- ????????????<tr?bgcolor="<s:if?test="#s.odd">pink</s:if>">??
- ????????????????<td><s:property?value="#s.index"/></td>??
- ????????????????<td><s:property/></td>??
- ????????????????<td><s:property?value="#s.even"/></td>??
- ????????????????<td><s:property?value="#s.odd"/></td>??
- ????????????????<td><s:property?value="#s.first"/></td>??
- ????????????????<td><s:property?value="#s.last"/></td>??
- ????????????????<td><s:property?value="#s.count"/></td>??
- ????????????</tr>??
- ????????</s:iterator>????????
- ?????</table>??
- ???????
- ???????
- ??????<br/>--------------------------<br/>??
- ?????#、merge?@和类似:用于将多个集合合并<br/>??
- ?????<s:set?name="merList1"?value="{'111','222','333','444'}"></s:set>??
- ?????<s:set?name="merList2"?value="{'aaa','bbb','ccc','ddd'}"></s:set>??
- ?????<s:append?var="newMerList">??
- ????????<s:param?value="merList1"></s:param>??
- ????????<s:param?value="merList2"></s:param>??
- ?????</s:append>??
- ?????<s:iterator?value="#newMerList">??
- ????????<s:property/>?|???
- ?????</s:iterator>??
- ??????<br/>--------------------------<br/>??
- ?????#、sort?@用于排序<br/>??
- ?????<s:bean?var="myComparator"?name="com.rao.comparator.MyComparator"></s:bean>??
- ?????<s:sort?comparator="#myComparator"?source="{1,45,56,0,345,3}">??
- ????????<s:iterator>??
- ????????????<s:property/>,??
- ????????</s:iterator>??
- ?????</s:sort>??
- ??????<br/>--------------------------<br/>??
- ?????#、subset?@用户截取集合中的子集;???注:decider:可选属性,指定由开发者自己决定是否选中该元素.????
- ?????<br/>??
- ?????<s:set?name="subList"?value="{'@@@','***','&&&','###'}"></s:set>??
- ?????<s:subset?source="#subList"?start="1"?count="2">??
- ????????<s:iterator>??
- ????????????<s:property/>,??
- ????????</s:iterator>??
- ?????</s:subset>??
- ??????<br/>--------------------------<br/>??
- ???????二、数据标签<br/>??
- ??????<hr?size="3"?color="red">??
- ????#、action?@用于导入一个Action<br/>??
- ????使用action标签,可以允许在jsp页面中直接调用Action,在调用Action时候,可以指定需要被调用的Action的name和namespace.如果指定了executeResult参数的属性值为true,该标签会把Action的处理结果(视图资源)包含到本页面中.?使用action标签指定属性有:??
- ????<br/>??
- ????id:?可选属性,作为该Action的引用ID???<br/>???
- ?????
- ????name:必选属性,指定调用Action????<br/>??
- ?????????
- ????namespace:可选属性,指定该标签调用Action所属namespace????<br/>??
- ?????????
- ????executeResult:可选属性,指定是否将Action的处理结果包含到本页面中.默认值为false,不包含.????<br/>??
- ?????????
- ????ignoreContextParam:可选参数,指定该页面的请求参数是否需要传入调用的Action中,默认值是false,即传入参数.<br/>??
- ??????
- ????s:param是以request方式的值的,而不是以参数传值,所以request.getParameter("")会获取不到值,通过request.getAttribute("")方式可以获取<br/>??
- ??
- ????<s:action?name="tagsAction1"?ignoreContextParams="true"?executeResult="true"?namespace="/com/rao">??
- ????????<s:param?name="userName"?value="'三毛'"></s:param>??
- ????</s:action>??
- ??????
- ??????<br/>--------------------------<br/>??
- ????#、bean?@用于导入一个javaBean,相当于:jsp:useBean?标签<br/>??
- ????<s:bean?name="com.rao.bean.UserBean"?var="user">??
- ????????<s:param?name="userId"?value="1001"></s:param>??
- ????????<s:param?name="userName"?value="'张三'"></s:param>??
- ????</s:bean>??
- ????userId:<s:property?value="#user.userId"/><br>??
- ????userName:<s:property?value="#user.userName"/>??
- ??????<br/>--------------------------<br/>??
- ????#、date?@用于格式化日期<br/>??
- ????<s:set?name="dt"?value="new?java.util.Date()"></s:set>??
- ????当期系统时间是:<s:date?name="dt"?format="yyyy-MM-dd?HH:ss:mm"/>??
- ??????<br/>--------------------------<br/>??
- ????#、debug?@用于调试程序,让开发人员一目了然的知道当前请求、值栈、栈中的各项参数<br/>??
- ????<s:debug/>??
- ??????<br/>--------------------------<br/>??
- ????#、i18n?@用于访问国际化资源文件的内容<br/>??
- ????????????????1.默认访问全局范围内的资源文件;??
- ????????????????<br>??
- ????????????????<s:text?name="welcome">??
- ????????????????????<s:param>三毛</s:param>??
- ????????????????????<s:param>学习</s:param>??
- ????????????????</s:text>??
- ??????????
- ????????????????<hr>??
- ????????????????2.访问包范围内的资源文件;??
- ????????????????<br>??
- ????????????????<s:i18n?name="com/rao/action/package">??
- ????????????????????<s:text?name="welcome">??
- ????????????????????????<s:param>三毛</s:param>??
- ????????????????????????<s:param>学习</s:param>??
- ????????????????????</s:text>??
- ????????????????</s:i18n>??
- ????????????????<hr>??
- ????????????????3.访问Action范围内的资源文件;??
- ????????????????<br>??
- ????????????????<s:i18n?name="com/rao/action/GlobalNativeAction">??
- ????????????????????<s:text?name="welcome">??
- ????????????????????????<s:param>三毛</s:param>??
- ????????????????????????<s:param>学习</s:param>??
- ????????????????????</s:text>??
- ????????????????</s:i18n>??
- ??????<br/>--------------------------<br/>??
- ????#、include?@用于导入一个jsp文件,等同于:jsp:include标签<br/>??
- ????<s:include?value="success.jsp"></s:include>??
- ??????<br/>--------------------------<br/>??
- ????#、param?@用于给指定参数设置值<br/>??
- ????<s:bean?name="com.rao.bean.UserBean"?var="user">??
- ????????<s:param?name="userId"?value="1001"></s:param>??
- ????????<s:param?name="userName"?value="'张三'"></s:param>??
- ????</s:bean>??
- ????userId:<s:property?value="#user.userId"/><br>??
- ????userName:<s:property?value="#user.userName"/>??
- ??????<br/>--------------------------<br/>??
- ????#、property?@输出结果,很像EL表达式,但是可以依托于OGNL表带是很强大<br/>??
- ????同上??
- ??????<br/>--------------------------<br/>??
- ????#、push?@该标签可以把程序员在ActionContext中引用的对像压入valuestack中,为以后访问对象提供了方便<br/>??
- ????<s:push?value="#request.user"><s:property?value="userName"/></s:push>??
- ??????<br/>--------------------------<br/>??
- ????#、set?@用户声明对象或属性<br/>??
- ????<s:set?name="uName"?value="#request.user.userName"></s:set>??
- ????<s:property?value="#uName"/>,你好啊!??
- ??????<br/>--------------------------<br/>??
- ????#、text?@用户获取国际化资源文件的内容<br/>??
- ????请参考?il8n标签??
- ??????<br/>--------------------------<br/>??
- ????#、url?@用于组拼一个请求路径<br/>??
- ????<s:url?var="url1"?action="MyAction"?method="add">??
- ????????<s:param?name="id"?value="%{23}"></s:param>??
- ????????<s:param?name="name"?value="%{'tom'}"></s:param>??
- ????</s:url>??
- ????<s:property?value="#url1"/>??
- ????<br/>??
- ????注意:<br/>?????
- ????????<s:set?name="myurl"?value="'http://www.baidu.com'"></s:set>?????
- ????????value以字符处理:???<s:url?value="#myurl"></s:url><br>?????
- ????????value明确指定以ognl表达式处理:????<s:url?value="%{#myurl}"></s:url>?????
- ??????
- ??????<br/>--------------------------<br/>??
- ??????
- ???????三、UI标签<br/>??
- ????<hr?size="3"?color="red">??
- ????<s:form>??
- ????#、checkboxlist?@复选框列表<br>??
- ?????????1>?.list?生成;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>?????
- ????????name:checkboxlist的名字<br>?????
- ????????list:checkboxlist要显示的列表<br>?????
- ????????value:checkboxlist默认被选中的选项,checked=checked<br>?????
- ????????<s:checkboxlist?theme="simple"?name="checkbox1"?list="{'上网','看书','爬山','游泳','唱歌'}"?value="{'上网','看书'}"?></s:checkboxlist>?????
- ????????<br>?????
- ?????????
- ????????2>?.Map?生成;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>?????
- ????????name:checkboxlist的名字<br>?????
- ????????list:checkboxlist要显示的列表<br>?????
- ????????listKey:checkbox?的value的值<br>?????
- ????????listValue:checkbox?的lablel(显示的值)<br>?????
- ????????value:checkboxlist默认被选中的选项,checked=checked<br>?????
- ????????<s:checkboxlist?theme="simple"?name="checkbox2"?list="#{1:'上网',2:'看书',3:'爬山',4:'游泳',5:'唱歌'}"?listKey="key"?listValue="value"?value="{1,2,5}"?></s:checkboxlist>?????
- ????
- ?????????<br/>--------------------------<br/>??
- ?????#、combobox?<br/>??
- ????<s:combobox?theme="simple"?label="选择你喜欢的颜色"?name="colorNames"??headerValue="------请选择------"?headerKey="1"??list="{'红','橙','黄','绿','青','蓝','紫'}"?/>???
- ????<br/>--------------------------<br/>??
- ?????#、radio?@单选框<br/>???
- ?????????<%?????
- ????????????Sex?sex1?=?new?Sex(1,"男");??????
- ????????????Sex?sex2?=?new?Sex(2,"女");?????
- ????????????List<Sex>?list?=?new?ArrayList<Sex>();??????
- ????????????list.add(sex1);?????
- ????????????list.add(sex2);?????
- ????????????request.setAttribute("sexs",list);??????
- ????????%>?????
- ??????????????????????这个与checkboxlist差不多;<br>?????
- ????????1>.如果集合为javabean:<s:radio?theme="simple"?name="sex"?list="#request.sexs"?listKey="id"?listValue="name"></s:radio><br>?????
- ????????2>.如果集合为list:<s:radio?theme="simple"?name="sexList"?list="{'男','女'}"></s:radio><br>?????
- ????????3>.如果集合为map:<s:radio?theme="simple"?name="sexMap"?list="#{1:'男',2:'女'}"?listKey="key"?listValue="value"></s:radio><br>?????
- ????????<hr>?????
- ?????<br/>--------------------------<br/>??
- ?????#、select?@下拉列表框<br/>????
- ????????这个与s:checkboxlist差不多;<br>?????
- ????????1>.如果集合为javabean:<s:select?theme="simple"?name="sex"?list="#request.sexs"?listKey="id"?listValue="name"></s:select><br>?????
- ????????2>.如果集合为list:<s:select?theme="simple"?name="sexList"?list="{'男','女'}"></s:select><br>?????
- ????????3>.如果集合为map:<s:select?theme="simple"?name="sexMap"?list="#{1:'男',2:'女'}"?listKey="key"?listValue="value"></s:select><br>?????
- ???????
- ?????<br/>--------------------------<br/>??
- ?????#、doubleselect?@级联菜单?<br/>??
- ????<!--???可以用直接指定,当然也可以跟数据库绑定的?-->??
- ?????<s:set?name="proviList"?value="{'江西省','湖北省'}"></s:set>??
- ?????<s:set?name="jxList"?value="{'南昌市','赣州市','九江市','上饶市','鹰潭市'}"></s:set>??
- ?????<s:set?name="hbList"?value="{'武汉市','恩施市','十堰市','荆州市','襄樊市'}"></s:set>??
- ?????<s:doubleselect?theme="simple"??name="provi"?doubleList="top=='江西省'???#jxList?:?#hbList"?list="#proviList"?doubleName="city"></s:doubleselect>??
- ?????<br/>--------------------------<br/>??
- ?????#、optiontransferselect?<br/>??
- ?????<s:optiontransferselect?theme="simple"?label="change"?name="abc"?doubleList="{'111','222','333','444'}"?list="{'aaa','bbb','ccc','ddd'}"?doubleName="number"></s:optiontransferselect>??
- ?????<br/>--------------------------<br/>??
- ?????#、updownselect?@可上下选择的select?<br/>??
- ?????<s:updownselect?label="selectCity"?emptyOption="true"?name="selectCity"?list="#jxList"?headerValue="-Please?Select?The?City-"?headerKey="-1"></s:updownselect>??
- ??????<br/>--------------------------<br/>??
- ?????#、sx:datetimepicker?@日期选择控件?<br/>??
- ?????使用步骤:声明:我这里用的是strut?2.1.8.1,在struts2.0的版本中可能有所不同;<br/>??
- ??????????????1.导入struts2-dojo-plugin-2.1.8.1.jar?DoJo?插件包;<br/>??
- ??????????????2.?导入标签:<%--@?taglib?prefix="sx"?uri="/struts-dojo-tags"--%>;<br/>??
- ??????????????3.在需要使用的页面中的head标签之间加上<%--?<sx:head?parseContent="true"/>?--%>;<br/>??
- ?????<sx:datetimepicker?label="birthday"?name="bir"?value="#dt"></sx:datetimepicker>??
- ??????<br/>--------------------------<br/>??
- ?????#、sx:tabbedpanel?@选项卡控件?<br/>??
- ??????声明:这个标签代码转至:http://blog.sina.com.cn/s/blog_6145ed810100ecud.html,版权归作者所有;写的挺好拿来大家共同学习。??
- ???????
- ??????<!--?tabbedpanel标签?-->??
- ????????<!--?最简单的选项卡,两个选项卡加载都是本页面?-->??
- ??????????<hr?color="blue">??
- ??????????<b>最简单的选项卡:</b>??
- ??????????<br>??
- ????????????????<sx:tabbedpanel?id="tab1"?beforeSelectTabNotifyTopics="/beforeSelect">??
- ?????????????<sx:div?label="Tab?1"?>??
- ?????????????????Local?Tab?1??
- ?????????????</sx:div>????
- ?????????????<sx:div?label="Tab?2"?>??
- ?????????????????Local?Tab?2??
- ?????????????</sx:div>????
- ????????????????</sx:tabbedpanel>??
- ??????????
- ??????????
- ????????<!--?加载其他页面的选项卡?-->??
- ??????????<hr?color="blue">??
- ??????????<b>加载其他页面的选项卡:</b>??
- ??????????<br>??
- ??????????<sx:tabbedpanel?id="tab2">??
- ??????????<sx:div?label="Remote?Tab?1"?href="upload.jsp">??
- ?????????????????????Remote?Tab?1??
- ????????????????</sx:div>??
- ?????????????<sx:div?label="Remote?Tab?2"?href="multipleUpload.jsp"?>??
- ?????????????????????Remote?Tab?1??
- ????????????????</sx:div>??
- ??????????</sx:tabbedpanel>??
- ??????????
- ??????????
- ????????<!--?设置选项卡底下的内容懒加载,即等需要的时候再加载,使用属性preload="false"-->??
- ??????????<hr?color="blue">??
- ??????????<b>设置选项卡底下的内容懒加载,即等需要的时候再加载,使用属性preload="false":</b>??
- ??????????<br>??
- ????????????????<sx:tabbedpanel?id="tab3">??
- ?????????????<sx:div?label="Remote?Tab?1"?href="upload.jsp">??
- ?????????????????Remote?Tab?1??
- ?????????????</sx:div>???
- ?????????????<sx:div?label="Remote?Tab?2"?href="multipleUpload.jsp"?preload="false">??
- ?????????????????Remote?Tab?1??
- ?????????????</sx:div>???????
- ????????????????</sx:tabbedpanel>??
- ??????????
- ??????????
- ????????<!--?固定大小的选项卡?-->??
- ??????????<hr?color="blue">??
- ??????????<b>固定大小的选项卡,使用属性cssStyle和doLayout:</b>??
- ??????????<br>??
- ????????????????<sx:tabbedpanel?cssStyle="width:?200px;?height:?100px;"?doLayout="true"?id="tab4">??
- ?????????????<sx:div?label="Tab?1"?>??
- ?????????????????Local?Tab?1??
- ?????????????</sx:div>????
- ?????????????<sx:div?label="Tab?2"?>??
- ?????????????????Local?Tab?2??
- ?????????????</sx:div>????
- ????????????????</sx:tabbedpanel>??
- ??????????
- ??????????
- ????????<!--?每次点击选项卡时都重新刷新内容?-->??
- ??????????<hr?color="blue">??
- ??????????<b>每次点击选项卡时都重新刷新内容,使用属性refreshOnShow:</b>??
- ??????????<br>??
- ??????????<sx:tabbedpanel?id="tab5">??
- ?????????????<sx:div?label="Remote?Tab?1"?href="upload.jsp"?refreshOnShow="true">??
- ?????????????????Remote?Tab?1??
- ?????????????</sx:div>???
- ?????????????<sx:div?label="Remote?Tab?2"?href="multipleUpload.jsp"?refreshOnShow="true">??
- ?????????????????Remote?Tab?2??
- ?????????????</sx:div>???????
- ??????????</sx:tabbedpanel>??
- ??????????
- ???????????
- ??????????
- ????????<!--?使得其中一个选项卡失效?-->??
- ??????????<hr?color="blue">??
- ??????????<b>使得其中一个选项卡失效:</b>??
- ??????????<br>??
- ?????????????????<sx:tabbedpanel?id="tab6">??
- ????????????<sx:div?label="Tab?1"?>??
- ????????????????Local?Tab?1??
- ????????????</sx:div>????
- ????????????<sx:div?label="Tab?2"?disabled="true">??
- ????????????????Local?Tab?2??
- ????????????</sx:div>????
- ????????????????</sx:tabbedpanel>??
- ??????????
- ??????????
- ????????<!--?设置选项卡在底部显示?(可以是:?top,?right,?bottom,?left)?-->??
- ??????????<hr?color="blue">??
- ??????????<b>设置选项卡在底部显示?(可以是:?top,?right,?bottom,?left):</b>??
- ??????????<br>??
- ??????????<sx:tabbedpanel?id="tab7"?labelposition="bottom"?cssStyle="width:200px;height:100px;"?doLayout="true">??
- ?????????????<sx:div?label="Tab?1"?>??
- ?????????????????Local?Tab?1??
- ?????????????</sx:div>????
- ?????????????<sx:div?label="Tab?2"?>??
- ?????????????????Local?Tab?2??
- ?????????????</sx:div>????
- ??????????</sx:tabbedpanel>??
- ??????????
- ????????<!--?设置选项卡允许关闭,使用属性closeable?-->??
- ??????????<hr?color="blue">??
- ??????????<b>设置选项卡允许关闭,使用属性closeable:</b>??
- ??????????<br>?????????
- ??????????<sx:tabbedpanel?id="tab8">??
- ?????????????<sx:div?label="Tab?1"?>??
- ?????????????????Local?Tab?1??
- ?????????????</sx:div>????
- ?????????????<sx:div?label="Tab?2"??closable="true">??
- ?????????????????Local?Tab?2??
- ?????????????</sx:div>????
- ??????????</sx:tabbedpanel>??
- ??
- ?????<br/>--------------------------<br/>??
- ?????#、sx:textarea?@textarea控件?<br/>??
- ?????<sx:textarea?label="简介"?value="sx:textareasx:textareasx:<br/>textareasx:textareasx:textareasx:<br/>textareasx:textareasx:<br/>textareasx:textarea"></sx:textarea>??
- ???????
- ?????<br/>--------------------------<br/>??
- ?????#、sx:tree?@树控件?<br/>??
- ?????<sx:tree?id="tree1"?label="根节点">??
- ???????<sx:treenode?id="tn1"?label="财务部"?/>??
- ???????<sx:treenode?id="tn2"?label="开发部">??
- ???????????<sx:treenode?id="tn3"?label="JAVA"?/>??
- ???????????<sx:treenode?id="tn4"?label=".NET"?/>??
- ???????</sx:treenode>??
- ???????<sx:treenode?id="tn5"?label="人事部"?/>??
- ????</sx:tree>??
- ???????
- ?</s:form>?????
- ???????
- ??</body>??
- </html>??
?
?
struts.xml 代码:
- <?xml?version="1.0"?encoding="UTF-8"?>??
- <!DOCTYPE?struts?PUBLIC?"-//Apache?Software?Foundation//DTD?Struts?Configuration?2.1.7//EN"?"struts-2.1.7.dtd"?>??
- <struts>??
- ????<constant?name="struts.custom.i18n.resources"?value="struts2"></constant>??
- ????<constant?name="struts.configuration.xml.reload"?value="true"></constant>??
- ??????
- ????<package?name="package1"?namespace="/com/rao"?extends="struts-default">??
- ????????<action?name="tagsAction1"?class="com.rao.action.TagsAction1">??
- ????????????<result>/success.jsp</result>??
- ??????????????
- ????????</action>??
- ????</package>??
- </struts>??
?
?TagsAction1.java 代码:
- package?com.rao.action;??
- ??
- import?com.opensymphony.xwork2.ActionSupport;??
- ??
- public?class?TagsAction1?extends?ActionSupport?{??
- ????private?String?userName;??
- ????public?String?getUserName()?{??
- ????????return?userName;??
- ????}??
- ????public?void?setUserName(String?userName)?{??
- ????????this.userName?=?userName;??
- ????}??
- ??
- ????@Override??
- ????public?String?execute()?throws?Exception?{??
- ??????????
- ????????return?SUCCESS;??
- ????}??
- ??
- }??
?
?
GlobalNativeAction.java
- package?com.rao.action;??
- ??
- import?com.opensymphony.xwork2.ActionContext;??
- import?com.opensymphony.xwork2.ActionSupport;??
- /**?
- ?*?演示的是在Action?中获取国际化资源文件中的内容?
- ?*?@author?Administrator?
- ?*?
- ?*/??
- public?class?GlobalNativeAction?extends?ActionSupport?{??
- ??
- ????@Override??
- ????public?String?execute()?throws?Exception?{??
- ????????//不带有占位符的获取方法??
- ????????//ActionContext.getContext().put("message",?this.getText("welcome"));??
- ????????//带有占位符的获取方法??
- ????????ActionContext.getContext().put("message",?this.getText("welcome",new?String[]{"raozhiyong","study"}));??
- ????????return?"message";??
- ????}??
- ??
- }??
?
?
struts2_zh_CN.properties
?
?
welcome?? | ?? 全局范围:{0},这是一个中文的国际化资源文件,欢迎你的使用{1}!!! |
?
GlobalNativeAction_zh_CN.properties
?
?
welcome?? | ?? Action范围:{0},这是一个中文的国际化资源文件,欢迎你的使用{1}!!! |
?
package_zh_CN.properties
?
?
welcome?? | ?? package范围:{0},这是一个中文的国际化资源文件,欢迎你的使用{1}!!! |
?
Sex.java
?
?
- package?com.rao.bean;??
- ??
- public?class?Sex?{??
- ????private?int?id;??
- ????private?String?name;??
- ??????
- ????public?Sex(int?id,?String?name)?{??
- ????????super();??
- ????????this.id?=?id;??
- ????????this.name?=?name;??
- ????}??
- ??????
- ????public?int?getId()?{??
- ????????return?id;??
- ????}??
- ????public?void?setId(int?id)?{??
- ????????this.id?=?id;??
- ????}??
- ????public?String?getName()?{??
- ????????return?name;??
- ????}??
- ????public?void?setName(String?name)?{??
- ????????this.name?=?name;??
- ????}??
- ??
- }??
?
?
UserBean.java
?
- package?com.rao.bean;??
- ??
- import?java.io.Serializable;??
- ??
- public?class?UserBean?implements?Serializable{??
- ??
- ????private?static?final?long?serialVersionUID?=?1L;??
- ????public?UserBean()?{}??
- ??????
- ????private?Integer?userId;??
- ????private?String?userName;??
- ????public?Integer?getUserId()?{??
- ????????return?userId;??
- ????}??
- ????public?void?setUserId(Integer?userId)?{??
- ????????this.userId?=?userId;??
- ????}??
- ????public?String?getUserName()?{??
- ????????return?userName;??
- ????}??
- ????public?void?setUserName(String?userName)?{??
- ????????this.userName?=?userName;??
- ????}??
- ??
- }??
?
?
MyComparator.java
?
?
- package?com.rao.comparator;??
- ??
- import?java.util.Comparator;??
- ??
- public?class?MyComparator?implements?Comparator<Integer>?{??
- ??
- ????public?int?compare(Integer?o1,?Integer?o2)?{??
- ????????int?c?=?o1.compareTo(o2);???
- ????????return?c;//可以完成顺序排序??
- ????????//return?-c;//可以完成倒序排序??
- ????}??
- }??
?
?运行结果,附上图片:
?
?
?
?
?
?
?
?
?
?
?代码见附件压缩包:Struts2-Tags.zip。谢谢!
?
?
?
?