当前位置: 代码迷 >> Web前端 >> struts 二 tag
  详细解决方案

struts 二 tag

热度:516   发布时间:2012-10-18 13:46:55.0
struts 2 tag

近学习? Struts 2.1 Tags 做了些笔记,贴出来大家一起学习下,希望大家多多交流。

?

别的都不说了,我就贴代码,代码里注释比较详细,呵呵。

文件目录,如下:

?

?

?index.jsp 代码

Java代码 ?收藏代码
  1. <%@?page?language="java"?import="java.util.*"?pageEncoding="UTF-8"%>??
  2. <%@page?import="com.rao.bean.Sex"%>??
  3. <%@?taglib?prefix="s"?uri="/struts-tags"%>??
  4. <%@?taglib?prefix="sx"?uri="/struts-dojo-tags"%>??
  5. <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN">??
  6. <html>??
  7. <head>??
  8. ??<title>My?page</title>??
  9. ??<s:head?theme="xhtml"/>??
  10. ??<sx:head?parseContent="true"/>??
  11. </head>??
  12. ??
  13. ??<body>??
  14. ????Struts?2.1?Tags??
  15. ????<br/>??
  16. ????<br/>??
  17. ????一、控制标签<br/><hr?size="3"?color="red">??
  18. ??????
  19. ?????#、if?/elseif/?else?@用于逻辑判断<br/>??
  20. ?????<s:set?name="bir"?value="-12"></s:set>??
  21. ?????<s:if?test="#bir>=180?||?#bir<0">??
  22. ????????你是何方妖怪???
  23. ?????</s:if>??
  24. ?????<s:elseif?test="#bir<=18?&&?#bir>=0">??
  25. ????????未成年人不能进入!??
  26. ?????</s:elseif>??
  27. ?????<s:elseif?test="#bir<=60?&&?#bir>=18">??
  28. ????????您已经成年!??
  29. ?????</s:elseif>??
  30. ?????<s:else>??
  31. ????????您已经老了!??
  32. ?????</s:else>??
  33. ?????<br/>--------------------------<br/>??
  34. ?????#、append?@用于将多个集合合并<br/>??
  35. ?????<s:set?name="appList1"?value="{'111','222','333','444'}"></s:set>??
  36. ?????<s:set?name="appList2"?value="{'aaa','bbb','ccc','ddd'}"></s:set>??
  37. ?????<s:append?var="newAppList">??
  38. ????????<s:param?value="appList1"></s:param>??
  39. ????????<s:param?value="appList2"></s:param>??
  40. ?????</s:append>??
  41. ?????<s:iterator?value="#newAppList">??
  42. ????????<s:property/>?|???
  43. ?????</s:iterator>??
  44. ??????<br/>--------------------------<br/>??
  45. ?????#、generator??<br/>??
  46. ?????generator 标签,该标签可以将指定字符串按指定分隔符分割成多个字串。生成的多个字串可以用iterator标签进行迭代输出。可以这么理解:generator标 签将一个字符串转换成一个List集合。在该标签体内,整个临时生成的集合将为Valuestack的顶端,但一旦该标签结束,生成的集合将被移除 Valuestack。generator标签有如下几个属性:??
  47. ????<br/>??
  48. ????1、count属性:指定生成集合中元素的总数。可选属性。<br/>??
  49. ??????
  50. ????2、val属性:必填属性,指定被解析的字符串。<br/>??
  51. ??????
  52. ????3、separator属性:这是一个必填属性,指定用于分割字符串的分隔符。<br/>??
  53. ??????
  54. ????4、 converter属性:可选属性,指定一个转换器,转换器负责将生成的集合中的每个字符串转换成对象,通过这个转换器可以将一个含有分隔符的字符串解析 成对象的集合。转换器必须一个继承org.apache.struts2.util.IteratorGenerator.Converter的对 象。??
  55. ????<br/>??
  56. ????5、var属性,可选属性。如果指定了该属性,则将生成的集合保存在Stack?Context中。如果不指定该属性,则将生成的集合放入ValueStack的顶端,该标签一结束,生成的集合就被移除。该属性也可替换成id。??
  57. ????<br/>??
  58. ?????<s:generator??val="'aaa,bbb,ccc,ddd'"??separator=","?count="2">??
  59. ????????<s:iterator>??
  60. ????????????<s:property/>??
  61. ????????</s:iterator>??
  62. ?????</s:generator><br/>??
  63. ??
  64. ??????<br/>--------------------------<br/>??
  65. ?????#、iterator?用于迭代数据<br/>??
  66. ?????<s:set?name="iterList"?value="{'aaa','bbb','ccc','ddd'}"></s:set>??
  67. ?????<table?border="1">??
  68. ?????<tr>?????
  69. ????????????????<td>???索引???</td>?????
  70. ????????????????<td>???值???</td>?????
  71. ????????????????<td>???奇????</td>?????
  72. ????????????????<td>???偶?????</td>?????
  73. ????????????????<td>???首?????</td>?????
  74. ????????????????<td>???尾?????</td>?????
  75. ????????????????<td>??当前迭代数量????</td>?????
  76. ????????????</tr>?????
  77. ???????
  78. ????????<s:iterator?value="{'aaa','bbb','ccc','ddd','eee','fff'}"?begin="1"?status="s">??
  79. ????????????<tr?bgcolor="<s:if?test="#s.odd">pink</s:if>">??
  80. ????????????????<td><s:property?value="#s.index"/></td>??
  81. ????????????????<td><s:property/></td>??
  82. ????????????????<td><s:property?value="#s.even"/></td>??
  83. ????????????????<td><s:property?value="#s.odd"/></td>??
  84. ????????????????<td><s:property?value="#s.first"/></td>??
  85. ????????????????<td><s:property?value="#s.last"/></td>??
  86. ????????????????<td><s:property?value="#s.count"/></td>??
  87. ????????????</tr>??
  88. ????????</s:iterator>????????
  89. ?????</table>??
  90. ???????
  91. ???????
  92. ??????<br/>--------------------------<br/>??
  93. ?????#、merge?@和类似:用于将多个集合合并<br/>??
  94. ?????<s:set?name="merList1"?value="{'111','222','333','444'}"></s:set>??
  95. ?????<s:set?name="merList2"?value="{'aaa','bbb','ccc','ddd'}"></s:set>??
  96. ?????<s:append?var="newMerList">??
  97. ????????<s:param?value="merList1"></s:param>??
  98. ????????<s:param?value="merList2"></s:param>??
  99. ?????</s:append>??
  100. ?????<s:iterator?value="#newMerList">??
  101. ????????<s:property/>?|???
  102. ?????</s:iterator>??
  103. ??????<br/>--------------------------<br/>??
  104. ?????#、sort?@用于排序<br/>??
  105. ?????<s:bean?var="myComparator"?name="com.rao.comparator.MyComparator"></s:bean>??
  106. ?????<s:sort?comparator="#myComparator"?source="{1,45,56,0,345,3}">??
  107. ????????<s:iterator>??
  108. ????????????<s:property/>,??
  109. ????????</s:iterator>??
  110. ?????</s:sort>??
  111. ??????<br/>--------------------------<br/>??
  112. ?????#、subset?@用户截取集合中的子集;???注:decider:可选属性,指定由开发者自己决定是否选中该元素.????
  113. ?????<br/>??
  114. ?????<s:set?name="subList"?value="{'@@@','***','&&&','###'}"></s:set>??
  115. ?????<s:subset?source="#subList"?start="1"?count="2">??
  116. ????????<s:iterator>??
  117. ????????????<s:property/>,??
  118. ????????</s:iterator>??
  119. ?????</s:subset>??
  120. ??????<br/>--------------------------<br/>??
  121. ???????二、数据标签<br/>??
  122. ??????<hr?size="3"?color="red">??
  123. ????#、action?@用于导入一个Action<br/>??
  124. ????使用action标签,可以允许在jsp页面中直接调用Action,在调用Action时候,可以指定需要被调用的Action的name和namespace.如果指定了executeResult参数的属性值为true,该标签会把Action的处理结果(视图资源)包含到本页面中.?使用action标签指定属性有:??
  125. ????<br/>??
  126. ????id:?可选属性,作为该Action的引用ID???<br/>???
  127. ?????
  128. ????name:必选属性,指定调用Action????<br/>??
  129. ?????????
  130. ????namespace:可选属性,指定该标签调用Action所属namespace????<br/>??
  131. ?????????
  132. ????executeResult:可选属性,指定是否将Action的处理结果包含到本页面中.默认值为false,不包含.????<br/>??
  133. ?????????
  134. ????ignoreContextParam:可选参数,指定该页面的请求参数是否需要传入调用的Action中,默认值是false,即传入参数.<br/>??
  135. ??????
  136. ????s:param是以request方式的值的,而不是以参数传值,所以request.getParameter("")会获取不到值,通过request.getAttribute("")方式可以获取<br/>??
  137. ??
  138. ????<s:action?name="tagsAction1"?ignoreContextParams="true"?executeResult="true"?namespace="/com/rao">??
  139. ????????<s:param?name="userName"?value="'三毛'"></s:param>??
  140. ????</s:action>??
  141. ??????
  142. ??????<br/>--------------------------<br/>??
  143. ????#、bean?@用于导入一个javaBean,相当于:jsp:useBean?标签<br/>??
  144. ????<s:bean?name="com.rao.bean.UserBean"?var="user">??
  145. ????????<s:param?name="userId"?value="1001"></s:param>??
  146. ????????<s:param?name="userName"?value="'张三'"></s:param>??
  147. ????</s:bean>??
  148. ????userId:<s:property?value="#user.userId"/><br>??
  149. ????userName:<s:property?value="#user.userName"/>??
  150. ??????<br/>--------------------------<br/>??
  151. ????#、date?@用于格式化日期<br/>??
  152. ????<s:set?name="dt"?value="new?java.util.Date()"></s:set>??
  153. ????当期系统时间是:<s:date?name="dt"?format="yyyy-MM-dd?HH:ss:mm"/>??
  154. ??????<br/>--------------------------<br/>??
  155. ????#、debug?@用于调试程序,让开发人员一目了然的知道当前请求、值栈、栈中的各项参数<br/>??
  156. ????<s:debug/>??
  157. ??????<br/>--------------------------<br/>??
  158. ????#、i18n?@用于访问国际化资源文件的内容<br/>??
  159. ????????????????1.默认访问全局范围内的资源文件;??
  160. ????????????????<br>??
  161. ????????????????<s:text?name="welcome">??
  162. ????????????????????<s:param>三毛</s:param>??
  163. ????????????????????<s:param>学习</s:param>??
  164. ????????????????</s:text>??
  165. ??????????
  166. ????????????????<hr>??
  167. ????????????????2.访问包范围内的资源文件;??
  168. ????????????????<br>??
  169. ????????????????<s:i18n?name="com/rao/action/package">??
  170. ????????????????????<s:text?name="welcome">??
  171. ????????????????????????<s:param>三毛</s:param>??
  172. ????????????????????????<s:param>学习</s:param>??
  173. ????????????????????</s:text>??
  174. ????????????????</s:i18n>??
  175. ????????????????<hr>??
  176. ????????????????3.访问Action范围内的资源文件;??
  177. ????????????????<br>??
  178. ????????????????<s:i18n?name="com/rao/action/GlobalNativeAction">??
  179. ????????????????????<s:text?name="welcome">??
  180. ????????????????????????<s:param>三毛</s:param>??
  181. ????????????????????????<s:param>学习</s:param>??
  182. ????????????????????</s:text>??
  183. ????????????????</s:i18n>??
  184. ??????<br/>--------------------------<br/>??
  185. ????#、include?@用于导入一个jsp文件,等同于:jsp:include标签<br/>??
  186. ????<s:include?value="success.jsp"></s:include>??
  187. ??????<br/>--------------------------<br/>??
  188. ????#、param?@用于给指定参数设置值<br/>??
  189. ????<s:bean?name="com.rao.bean.UserBean"?var="user">??
  190. ????????<s:param?name="userId"?value="1001"></s:param>??
  191. ????????<s:param?name="userName"?value="'张三'"></s:param>??
  192. ????</s:bean>??
  193. ????userId:<s:property?value="#user.userId"/><br>??
  194. ????userName:<s:property?value="#user.userName"/>??
  195. ??????<br/>--------------------------<br/>??
  196. ????#、property?@输出结果,很像EL表达式,但是可以依托于OGNL表带是很强大<br/>??
  197. ????同上??
  198. ??????<br/>--------------------------<br/>??
  199. ????#、push?@该标签可以把程序员在ActionContext中引用的对像压入valuestack中,为以后访问对象提供了方便<br/>??
  200. ????<s:push?value="#request.user"><s:property?value="userName"/></s:push>??
  201. ??????<br/>--------------------------<br/>??
  202. ????#、set?@用户声明对象或属性<br/>??
  203. ????<s:set?name="uName"?value="#request.user.userName"></s:set>??
  204. ????<s:property?value="#uName"/>,你好啊!??
  205. ??????<br/>--------------------------<br/>??
  206. ????#、text?@用户获取国际化资源文件的内容<br/>??
  207. ????请参考?il8n标签??
  208. ??????<br/>--------------------------<br/>??
  209. ????#、url?@用于组拼一个请求路径<br/>??
  210. ????<s:url?var="url1"?action="MyAction"?method="add">??
  211. ????????<s:param?name="id"?value="%{23}"></s:param>??
  212. ????????<s:param?name="name"?value="%{'tom'}"></s:param>??
  213. ????</s:url>??
  214. ????<s:property?value="#url1"/>??
  215. ????<br/>??
  216. ????注意:<br/>?????
  217. ????????<s:set?name="myurl"?value="'http://www.baidu.com'"></s:set>?????
  218. ????????value以字符处理:???<s:url?value="#myurl"></s:url><br>?????
  219. ????????value明确指定以ognl表达式处理:????<s:url?value="%{#myurl}"></s:url>?????
  220. ??????
  221. ??????<br/>--------------------------<br/>??
  222. ??????
  223. ???????三、UI标签<br/>??
  224. ????<hr?size="3"?color="red">??
  225. ????<s:form>??
  226. ????#、checkboxlist?@复选框列表<br>??
  227. ?????????1>?.list?生成;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>?????
  228. ????????name:checkboxlist的名字<br>?????
  229. ????????list:checkboxlist要显示的列表<br>?????
  230. ????????value:checkboxlist默认被选中的选项,checked=checked<br>?????
  231. ????????<s:checkboxlist?theme="simple"?name="checkbox1"?list="{'上网','看书','爬山','游泳','唱歌'}"?value="{'上网','看书'}"?></s:checkboxlist>?????
  232. ????????<br>?????
  233. ?????????
  234. ????????2>?.Map?生成;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>?????
  235. ????????name:checkboxlist的名字<br>?????
  236. ????????list:checkboxlist要显示的列表<br>?????
  237. ????????listKey:checkbox?的value的值<br>?????
  238. ????????listValue:checkbox?的lablel(显示的值)<br>?????
  239. ????????value:checkboxlist默认被选中的选项,checked=checked<br>?????
  240. ????????<s:checkboxlist?theme="simple"?name="checkbox2"?list="#{1:'上网',2:'看书',3:'爬山',4:'游泳',5:'唱歌'}"?listKey="key"?listValue="value"?value="{1,2,5}"?></s:checkboxlist>?????
  241. ????
  242. ?????????<br/>--------------------------<br/>??
  243. ?????#、combobox?<br/>??
  244. ????<s:combobox?theme="simple"?label="选择你喜欢的颜色"?name="colorNames"??headerValue="------请选择------"?headerKey="1"??list="{'红','橙','黄','绿','青','蓝','紫'}"?/>???
  245. ????<br/>--------------------------<br/>??
  246. ?????#、radio?@单选框<br/>???
  247. ?????????<%?????
  248. ????????????Sex?sex1?=?new?Sex(1,"男");??????
  249. ????????????Sex?sex2?=?new?Sex(2,"女");?????
  250. ????????????List<Sex>?list?=?new?ArrayList<Sex>();??????
  251. ????????????list.add(sex1);?????
  252. ????????????list.add(sex2);?????
  253. ????????????request.setAttribute("sexs",list);??????
  254. ????????%>?????
  255. ??????????????????????这个与checkboxlist差不多;<br>?????
  256. ????????1>.如果集合为javabean:<s:radio?theme="simple"?name="sex"?list="#request.sexs"?listKey="id"?listValue="name"></s:radio><br>?????
  257. ????????2>.如果集合为list:<s:radio?theme="simple"?name="sexList"?list="{'男','女'}"></s:radio><br>?????
  258. ????????3>.如果集合为map:<s:radio?theme="simple"?name="sexMap"?list="#{1:'男',2:'女'}"?listKey="key"?listValue="value"></s:radio><br>?????
  259. ????????<hr>?????
  260. ?????<br/>--------------------------<br/>??
  261. ?????#、select?@下拉列表框<br/>????
  262. ????????这个与s:checkboxlist差不多;<br>?????
  263. ????????1>.如果集合为javabean:<s:select?theme="simple"?name="sex"?list="#request.sexs"?listKey="id"?listValue="name"></s:select><br>?????
  264. ????????2>.如果集合为list:<s:select?theme="simple"?name="sexList"?list="{'男','女'}"></s:select><br>?????
  265. ????????3>.如果集合为map:<s:select?theme="simple"?name="sexMap"?list="#{1:'男',2:'女'}"?listKey="key"?listValue="value"></s:select><br>?????
  266. ???????
  267. ?????<br/>--------------------------<br/>??
  268. ?????#、doubleselect?@级联菜单?<br/>??
  269. ????<!--???可以用直接指定,当然也可以跟数据库绑定的?-->??
  270. ?????<s:set?name="proviList"?value="{'江西省','湖北省'}"></s:set>??
  271. ?????<s:set?name="jxList"?value="{'南昌市','赣州市','九江市','上饶市','鹰潭市'}"></s:set>??
  272. ?????<s:set?name="hbList"?value="{'武汉市','恩施市','十堰市','荆州市','襄樊市'}"></s:set>??
  273. ?????<s:doubleselect?theme="simple"??name="provi"?doubleList="top=='江西省'???#jxList?:?#hbList"?list="#proviList"?doubleName="city"></s:doubleselect>??
  274. ?????<br/>--------------------------<br/>??
  275. ?????#、optiontransferselect?<br/>??
  276. ?????<s:optiontransferselect?theme="simple"?label="change"?name="abc"?doubleList="{'111','222','333','444'}"?list="{'aaa','bbb','ccc','ddd'}"?doubleName="number"></s:optiontransferselect>??
  277. ?????<br/>--------------------------<br/>??
  278. ?????#、updownselect?@可上下选择的select?<br/>??
  279. ?????<s:updownselect?label="selectCity"?emptyOption="true"?name="selectCity"?list="#jxList"?headerValue="-Please?Select?The?City-"?headerKey="-1"></s:updownselect>??
  280. ??????<br/>--------------------------<br/>??
  281. ?????#、sx:datetimepicker?@日期选择控件?<br/>??
  282. ?????使用步骤:声明:我这里用的是strut?2.1.8.1,在struts2.0的版本中可能有所不同;<br/>??
  283. ??????????????1.导入struts2-dojo-plugin-2.1.8.1.jar?DoJo?插件包;<br/>??
  284. ??????????????2.?导入标签:<%--@?taglib?prefix="sx"?uri="/struts-dojo-tags"--%>;<br/>??
  285. ??????????????3.在需要使用的页面中的head标签之间加上<%--?<sx:head?parseContent="true"/>?--%>;<br/>??
  286. ?????<sx:datetimepicker?label="birthday"?name="bir"?value="#dt"></sx:datetimepicker>??
  287. ??????<br/>--------------------------<br/>??
  288. ?????#、sx:tabbedpanel?@选项卡控件?<br/>??
  289. ??????声明:这个标签代码转至:http://blog.sina.com.cn/s/blog_6145ed810100ecud.html,版权归作者所有;写的挺好拿来大家共同学习。??
  290. ???????
  291. ??????<!--?tabbedpanel标签?-->??
  292. ????????<!--?最简单的选项卡,两个选项卡加载都是本页面?-->??
  293. ??????????<hr?color="blue">??
  294. ??????????<b>最简单的选项卡:</b>??
  295. ??????????<br>??
  296. ????????????????<sx:tabbedpanel?id="tab1"?beforeSelectTabNotifyTopics="/beforeSelect">??
  297. ?????????????<sx:div?label="Tab?1"?>??
  298. ?????????????????Local?Tab?1??
  299. ?????????????</sx:div>????
  300. ?????????????<sx:div?label="Tab?2"?>??
  301. ?????????????????Local?Tab?2??
  302. ?????????????</sx:div>????
  303. ????????????????</sx:tabbedpanel>??
  304. ??????????
  305. ??????????
  306. ????????<!--?加载其他页面的选项卡?-->??
  307. ??????????<hr?color="blue">??
  308. ??????????<b>加载其他页面的选项卡:</b>??
  309. ??????????<br>??
  310. ??????????<sx:tabbedpanel?id="tab2">??
  311. ??????????<sx:div?label="Remote?Tab?1"?href="upload.jsp">??
  312. ?????????????????????Remote?Tab?1??
  313. ????????????????</sx:div>??
  314. ?????????????<sx:div?label="Remote?Tab?2"?href="multipleUpload.jsp"?>??
  315. ?????????????????????Remote?Tab?1??
  316. ????????????????</sx:div>??
  317. ??????????</sx:tabbedpanel>??
  318. ??????????
  319. ??????????
  320. ????????<!--?设置选项卡底下的内容懒加载,即等需要的时候再加载,使用属性preload="false"-->??
  321. ??????????<hr?color="blue">??
  322. ??????????<b>设置选项卡底下的内容懒加载,即等需要的时候再加载,使用属性preload="false":</b>??
  323. ??????????<br>??
  324. ????????????????<sx:tabbedpanel?id="tab3">??
  325. ?????????????<sx:div?label="Remote?Tab?1"?href="upload.jsp">??
  326. ?????????????????Remote?Tab?1??
  327. ?????????????</sx:div>???
  328. ?????????????<sx:div?label="Remote?Tab?2"?href="multipleUpload.jsp"?preload="false">??
  329. ?????????????????Remote?Tab?1??
  330. ?????????????</sx:div>???????
  331. ????????????????</sx:tabbedpanel>??
  332. ??????????
  333. ??????????
  334. ????????<!--?固定大小的选项卡?-->??
  335. ??????????<hr?color="blue">??
  336. ??????????<b>固定大小的选项卡,使用属性cssStyle和doLayout:</b>??
  337. ??????????<br>??
  338. ????????????????<sx:tabbedpanel?cssStyle="width:?200px;?height:?100px;"?doLayout="true"?id="tab4">??
  339. ?????????????<sx:div?label="Tab?1"?>??
  340. ?????????????????Local?Tab?1??
  341. ?????????????</sx:div>????
  342. ?????????????<sx:div?label="Tab?2"?>??
  343. ?????????????????Local?Tab?2??
  344. ?????????????</sx:div>????
  345. ????????????????</sx:tabbedpanel>??
  346. ??????????
  347. ??????????
  348. ????????<!--?每次点击选项卡时都重新刷新内容?-->??
  349. ??????????<hr?color="blue">??
  350. ??????????<b>每次点击选项卡时都重新刷新内容,使用属性refreshOnShow:</b>??
  351. ??????????<br>??
  352. ??????????<sx:tabbedpanel?id="tab5">??
  353. ?????????????<sx:div?label="Remote?Tab?1"?href="upload.jsp"?refreshOnShow="true">??
  354. ?????????????????Remote?Tab?1??
  355. ?????????????</sx:div>???
  356. ?????????????<sx:div?label="Remote?Tab?2"?href="multipleUpload.jsp"?refreshOnShow="true">??
  357. ?????????????????Remote?Tab?2??
  358. ?????????????</sx:div>???????
  359. ??????????</sx:tabbedpanel>??
  360. ??????????
  361. ???????????
  362. ??????????
  363. ????????<!--?使得其中一个选项卡失效?-->??
  364. ??????????<hr?color="blue">??
  365. ??????????<b>使得其中一个选项卡失效:</b>??
  366. ??????????<br>??
  367. ?????????????????<sx:tabbedpanel?id="tab6">??
  368. ????????????<sx:div?label="Tab?1"?>??
  369. ????????????????Local?Tab?1??
  370. ????????????</sx:div>????
  371. ????????????<sx:div?label="Tab?2"?disabled="true">??
  372. ????????????????Local?Tab?2??
  373. ????????????</sx:div>????
  374. ????????????????</sx:tabbedpanel>??
  375. ??????????
  376. ??????????
  377. ????????<!--?设置选项卡在底部显示?(可以是:?top,?right,?bottom,?left)?-->??
  378. ??????????<hr?color="blue">??
  379. ??????????<b>设置选项卡在底部显示?(可以是:?top,?right,?bottom,?left):</b>??
  380. ??????????<br>??
  381. ??????????<sx:tabbedpanel?id="tab7"?labelposition="bottom"?cssStyle="width:200px;height:100px;"?doLayout="true">??
  382. ?????????????<sx:div?label="Tab?1"?>??
  383. ?????????????????Local?Tab?1??
  384. ?????????????</sx:div>????
  385. ?????????????<sx:div?label="Tab?2"?>??
  386. ?????????????????Local?Tab?2??
  387. ?????????????</sx:div>????
  388. ??????????</sx:tabbedpanel>??
  389. ??????????
  390. ????????<!--?设置选项卡允许关闭,使用属性closeable?-->??
  391. ??????????<hr?color="blue">??
  392. ??????????<b>设置选项卡允许关闭,使用属性closeable:</b>??
  393. ??????????<br>?????????
  394. ??????????<sx:tabbedpanel?id="tab8">??
  395. ?????????????<sx:div?label="Tab?1"?>??
  396. ?????????????????Local?Tab?1??
  397. ?????????????</sx:div>????
  398. ?????????????<sx:div?label="Tab?2"??closable="true">??
  399. ?????????????????Local?Tab?2??
  400. ?????????????</sx:div>????
  401. ??????????</sx:tabbedpanel>??
  402. ??
  403. ?????<br/>--------------------------<br/>??
  404. ?????#、sx:textarea?@textarea控件?<br/>??
  405. ?????<sx:textarea?label="简介"?value="sx:textareasx:textareasx:<br/>textareasx:textareasx:textareasx:<br/>textareasx:textareasx:<br/>textareasx:textarea"></sx:textarea>??
  406. ???????
  407. ?????<br/>--------------------------<br/>??
  408. ?????#、sx:tree?@树控件?<br/>??
  409. ?????<sx:tree?id="tree1"?label="根节点">??
  410. ???????<sx:treenode?id="tn1"?label="财务部"?/>??
  411. ???????<sx:treenode?id="tn2"?label="开发部">??
  412. ???????????<sx:treenode?id="tn3"?label="JAVA"?/>??
  413. ???????????<sx:treenode?id="tn4"?label=".NET"?/>??
  414. ???????</sx:treenode>??
  415. ???????<sx:treenode?id="tn5"?label="人事部"?/>??
  416. ????</sx:tree>??
  417. ???????
  418. ?</s:form>?????
  419. ???????
  420. ??</body>??
  421. </html>??

?

?

struts.xml 代码:

Xml代码 ?收藏代码
  1. <?xml?version="1.0"?encoding="UTF-8"?>??
  2. <!DOCTYPE?struts?PUBLIC?"-//Apache?Software?Foundation//DTD?Struts?Configuration?2.1.7//EN"?"struts-2.1.7.dtd"?>??
  3. <struts>??
  4. ????<constant?name="struts.custom.i18n.resources"?value="struts2"></constant>??
  5. ????<constant?name="struts.configuration.xml.reload"?value="true"></constant>??
  6. ??????
  7. ????<package?name="package1"?namespace="/com/rao"?extends="struts-default">??
  8. ????????<action?name="tagsAction1"?class="com.rao.action.TagsAction1">??
  9. ????????????<result>/success.jsp</result>??
  10. ??????????????
  11. ????????</action>??
  12. ????</package>??
  13. </struts>??

?

?TagsAction1.java 代码:

Java代码 ?收藏代码
  1. package?com.rao.action;??
  2. ??
  3. import?com.opensymphony.xwork2.ActionSupport;??
  4. ??
  5. public?class?TagsAction1?extends?ActionSupport?{??
  6. ????private?String?userName;??
  7. ????public?String?getUserName()?{??
  8. ????????return?userName;??
  9. ????}??
  10. ????public?void?setUserName(String?userName)?{??
  11. ????????this.userName?=?userName;??
  12. ????}??
  13. ??
  14. ????@Override??
  15. ????public?String?execute()?throws?Exception?{??
  16. ??????????
  17. ????????return?SUCCESS;??
  18. ????}??
  19. ??
  20. }??

?

?

GlobalNativeAction.java

Java代码 ?收藏代码
  1. package?com.rao.action;??
  2. ??
  3. import?com.opensymphony.xwork2.ActionContext;??
  4. import?com.opensymphony.xwork2.ActionSupport;??
  5. /**?
  6. ?*?演示的是在Action?中获取国际化资源文件中的内容?
  7. ?*?@author?Administrator?
  8. ?*?
  9. ?*/??
  10. public?class?GlobalNativeAction?extends?ActionSupport?{??
  11. ??
  12. ????@Override??
  13. ????public?String?execute()?throws?Exception?{??
  14. ????????//不带有占位符的获取方法??
  15. ????????//ActionContext.getContext().put("message",?this.getText("welcome"));??
  16. ????????//带有占位符的获取方法??
  17. ????????ActionContext.getContext().put("message",?this.getText("welcome",new?String[]{"raozhiyong","study"}));??
  18. ????????return?"message";??
  19. ????}??
  20. ??
  21. }??

?

?

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

?

?

Java代码 ?收藏代码
  1. package?com.rao.bean;??
  2. ??
  3. public?class?Sex?{??
  4. ????private?int?id;??
  5. ????private?String?name;??
  6. ??????
  7. ????public?Sex(int?id,?String?name)?{??
  8. ????????super();??
  9. ????????this.id?=?id;??
  10. ????????this.name?=?name;??
  11. ????}??
  12. ??????
  13. ????public?int?getId()?{??
  14. ????????return?id;??
  15. ????}??
  16. ????public?void?setId(int?id)?{??
  17. ????????this.id?=?id;??
  18. ????}??
  19. ????public?String?getName()?{??
  20. ????????return?name;??
  21. ????}??
  22. ????public?void?setName(String?name)?{??
  23. ????????this.name?=?name;??
  24. ????}??
  25. ??
  26. }??

?

?

UserBean.java

?

Java代码 ?收藏代码
  1. package?com.rao.bean;??
  2. ??
  3. import?java.io.Serializable;??
  4. ??
  5. public?class?UserBean?implements?Serializable{??
  6. ??
  7. ????private?static?final?long?serialVersionUID?=?1L;??
  8. ????public?UserBean()?{}??
  9. ??????
  10. ????private?Integer?userId;??
  11. ????private?String?userName;??
  12. ????public?Integer?getUserId()?{??
  13. ????????return?userId;??
  14. ????}??
  15. ????public?void?setUserId(Integer?userId)?{??
  16. ????????this.userId?=?userId;??
  17. ????}??
  18. ????public?String?getUserName()?{??
  19. ????????return?userName;??
  20. ????}??
  21. ????public?void?setUserName(String?userName)?{??
  22. ????????this.userName?=?userName;??
  23. ????}??
  24. ??
  25. }??

?

?

MyComparator.java

?

?

Java代码 ?收藏代码
  1. package?com.rao.comparator;??
  2. ??
  3. import?java.util.Comparator;??
  4. ??
  5. public?class?MyComparator?implements?Comparator<Integer>?{??
  6. ??
  7. ????public?int?compare(Integer?o1,?Integer?o2)?{??
  8. ????????int?c?=?o1.compareTo(o2);???
  9. ????????return?c;//可以完成顺序排序??
  10. ????????//return?-c;//可以完成倒序排序??
  11. ????}??
  12. }??

?

?运行结果,附上图片:

?


?

?

?

?

?

?

?

?

?

?代码见附件压缩包:Struts2-Tags.zip。谢谢!

?

?

?

?

  相关解决方案