Struts2常用标签

http://www.blogjava.net/bulktree/archive/2008/01/04/172859.html

这些都是Struts2的一些新标签,感觉很新鲜,特别是datetimedipacker标志感觉很好

filevalidateExample.jsp 文件
  1. <%@ page language="java" c   
  2.     pageEncoding="ISO-8859-5"%>   
  3. <%@ taglib prefix="s" uri="/struts-tags"%>   
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">   
  5. <html>   
  6. <head>   
  7. <title>fieldValidatorsExample test</title>   
  8. <s:url id="siteCss" includeC   
  9.     value="/validationExamplesStyles.css" />   
  10. <s:head theme="xhtml" />   
  11.   
  12. </head>   
  13. <body>   
  14. <h3>All field Error will show</h3>   
  15. <s:fielderror />   
  16. <hr color="red" />   
  17.   
  18. <s:form action="fieldValidators" method="post">   
  19.     <s:textfield tooltip="ENTER YOUR NAME" label="YOUR NAME" name="name" />   
  20.     <s:textfield tooltip="ENTER YOUR AGE" label="YOUR AGE" name="age" />   
  21.   
  22.     <s:datetimepicker tooltip="ENTER YOUR BIRTHDAY" label="YOUR BIRTHDAY"  
  23.         name="birthday" />   
  24.   
  25.     <s:textfield tooltip="ENTER YOUR EMAIL" label="YOUR EMAIL" name="Email" />   
  26.     <s:textfield tooltip="ENTER YOUR URL" label="YOUR URL" name="url" />   
  27.   
  28.     <s:select tooltip="SELECT YOUR PROGRAM" label="YOUR PROGRAM"  
  29.         name="program" list="{'Java','.net','C#','Struts2'}" />   
  30.   
  31.     <s:checkboxlist tooltip="SELECT YOUR FAVOURITE COLOR"  
  32.         label="FAVOURITE COLOR" name="color"  
  33.         list="{'red','green','yellow','pink','blue'}" value="{'green','blue'}" />   
  34.   
  35.     <s:tree label="parent" id="parentId" theme="ajax"  
  36.         templateCssPath="/struts/tree.css" showRootGrid="true" showGrid="true">   
  37.         <s:treenode theme="ajax" label="child1" id="child1Id">   
  38.             <s:treenode theme="ajax" label="grandchild1" id="grandchild1Id" />   
  39.             <s:treenode theme="ajax" label="grandchild2" id="grandchild2Id" />   
  40.             <s:treenode theme="ajax" label="grandchild3" id="grandchild3Id" />   
  41.         </s:treenode>   
  42.   
  43.         <s:treenode theme="ajax" label="child2" id="child2Id" />   
  44.         <s:treenode theme="ajax" label="child3" id="child3Id" />   
  45.         <s:treenode theme="ajax" label="child4" id="child4Id" />   
  46.         <s:treenode theme="ajax" label="child5" id="child5Id">   
  47.             <s:treenode theme="ajax" label="gChild1" id="gChild1Id" />   
  48.             <s:treenode theme="ajax" label="gChild2" id="gChild2Id" />   
  49.         </s:treenode>   
  50.     </s:tree>   
  51.   
  52.     <s:hidden name="hiddenName" value="bulktree and oakertree" />   
  53.     <s:submit label="SUBMIT" />   
  54.   
  55. </s:form>   
  56.   
  57. </body>   
  58. </html>  
<%@ page language="java" c pageEncoding="ISO-8859-5"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>fieldValidatorsExample test</title> <s:url id="siteCss" includeC value="/validationExamplesStyles.css" /> <s:head theme="xhtml" /> </head> <body> <h3>All field Error will show</h3> <s:fielderror /> <hr color="red" /> <s:form action="fieldValidators" method="post"> <s:textfield tooltip="ENTER YOUR NAME" label="YOUR NAME" name="name" /> <s:textfield tooltip="ENTER YOUR AGE" label="YOUR AGE" name="age" /> <s:datetimepicker tooltip="ENTER YOUR BIRTHDAY" label="YOUR BIRTHDAY" name="birthday" /> <s:textfield tooltip="ENTER YOUR EMAIL" label="YOUR EMAIL" name="Email" /> <s:textfield tooltip="ENTER YOUR URL" label="YOUR URL" name="url" /> <s:select tooltip="SELECT YOUR PROGRAM" label="YOUR PROGRAM" name="program" list="{'Java','.net','C#','Struts2'}" /> <s:checkboxlist tooltip="SELECT YOUR FAVOURITE COLOR" label="FAVOURITE COLOR" name="color" list="{'red','green','yellow','pink','blue'}" value="{'green','blue'}" /> <s:tree label="parent" id="parentId" theme="ajax" templateCssPath="/struts/tree.css" showRootGrid="true" showGrid="true"> <s:treenode theme="ajax" label="child1" id="child1Id"> <s:treenode theme="ajax" label="grandchild1" id="grandchild1Id" /> <s:treenode theme="ajax" label="grandchild2" id="grandchild2Id" /> <s:treenode theme="ajax" label="grandchild3" id="grandchild3Id" /> </s:treenode> <s:treenode theme="ajax" label="child2" id="child2Id" /> <s:treenode theme="ajax" label="child3" id="child3Id" /> <s:treenode theme="ajax" label="child4" id="child4Id" /> <s:treenode theme="ajax" label="child5" id="child5Id"> <s:treenode theme="ajax" label="gChild1" id="gChild1Id" /> <s:treenode theme="ajax" label="gChild2" id="gChild2Id" /> </s:treenode> </s:tree> <s:hidden name="hiddenName" value="bulktree and oakertree" /> <s:submit label="SUBMIT" /> </s:form> </body> </html>
FileValidateAction.java文件
  1. package com.bulktree.struts2;   
  2.   
  3. import java.util.Date;   
  4.   
  5. import com.opensymphony.xwork2.ActionSupport;   
  6.   
  7. public class FieldValidatorsAction extends ActionSupport {   
  8.     private String name = null;   
  9.     private Integer age = null;   
  10.     private Date birthday = null;   
  11.     private String Email = null;   
  12.     private String url = null;   
  13.     private String program = null;   
  14.     private String color = null;   
  15.     private String hiddenName = null;   
  16.     private String child2 = null;   
  17.        
  18.        
  19.        
  20.     public String getChild2() {   
  21.         return child2;   
  22.     }   
  23.     public void setChild2(String child2) {   
  24.         this.child2 = child2;   
  25.     }   
  26.     public String getHiddenName() {   
  27.         return hiddenName;   
  28.     }   
  29.     public void setHiddenName(String hiddenName) {   
  30.         this.hiddenName = hiddenName;   
  31.     }   
  32.     public String getColor() {   
  33.         return color;   
  34.     }   
  35.     public void setColor(String color) {   
  36.         this.color = color;   
  37.     }   
  38.     public String getProgram() {   
  39.         return program;   
  40.     }   
  41.     public void setProgram(String program) {   
  42.         System.out.println("*****setProgram**********");   
  43.         this.program = program;   
  44.     }   
  45.     public String getName() {   
  46.         return name;   
  47.     }   
  48.     public void setName(String name) {   
  49.         this.name = name;   
  50.     }   
  51.     public Integer getAge() {   
  52.         return age;   
  53.     }   
  54.     public void setAge(Integer age) {   
  55.         this.age = age;   
  56.     }   
  57.     public Date getBirthday() {   
  58.         return birthday;   
  59.     }   
  60.     public void setBirthday(Date birthday) {   
  61.         this.birthday = birthday;   
  62.     }   
  63.     public String getEmail() {   
  64.         return Email;   
  65.     }   
  66.     public void setEmail(String email) {   
  67.         Email = email;   
  68.     }   
  69.     public String getUrl() {   
  70.         return url;   
  71.     }   
  72.     public void setUrl(String url) {   
  73.         this.url = url;   
  74.     }   
  75.        
  76.     @Override  
  77.     public String execute() throws Exception {   
  78.            
  79.         return SUCCESS;   
  80.     }   
  81.        
  82.     @Override  
  83.     public void validate() {           
  84.     }       
  85. }  
package com.bulktree.struts2; import java.util.Date; import com.opensymphony.xwork2.ActionSupport; public class FieldValidatorsAction extends ActionSupport { private String name = null; private Integer age = null; private Date birthday = null; private String Email = null; private String url = null; private String program = null; private String color = null; private String hiddenName = null; private String child2 = null; public String getChild2() { return child2; } public void setChild2(String child2) { this.child2 = child2; } public String getHiddenName() { return hiddenName; } public void setHiddenName(String hiddenName) { this.hiddenName = hiddenName; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public String getProgram() { return program; } public void setProgram(String program) { System.out.println("*****setProgram**********"); this.program = program; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public String getEmail() { return Email; } public void setEmail(String email) { Email = email; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } @Override public String execute() throws Exception { return SUCCESS; } @Override public void validate() { } }

struts.xml配置片段
  1. <action name="fieldValidators"  
  2.             class="com.bulktree.struts2.FieldValidatorsAction">  
  3.             <result>/welcome.jsp</result>  
  4.         </action>  
<action name="fieldValidators" class="com.bulktree.struts2.FieldValidatorsAction"> <result>/welcome.jsp</result> </action>

welcome.jsp显示页面
  1. <%@ page language="java" c   
  2.     pageEncoding="GB2312"%>   
  3. <%@ taglib prefix="s" uri="/struts-tags"%>   
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">   
  5. <html>   
  6. <head>   
  7. <meta http-equiv="Content-Type" c>   
  8. <title>login</title>   
  9. </head>   
  10. <body>   
  11. YOUR USERNAME:   
  12. <FONT size="5" color="red"><s:property value="username" /></FONT>   
  13. <br>   
  14. YOUR PASSWORD:   
  15. <FONT size="5" color="red"><s:property value="password" /></FONT>   
  16. <br>   
  17.   
  18. YOUR USERNAME:   
  19. <FONT size="5" color="red"><s:property value="user.username" /></FONT>   
  20. <br>   
  21. YOUR PASSWORD:   
  22. <FONT size="5" color="red"><s:property value="user.password" /></FONT>   
  23. <br>   
  24.   
  25. YOUR NAME:   
  26. <FONT size="5" color="red"><s:property value="name" /></FONT>   
  27. <br>   
  28. YOUR AGE:   
  29. <FONT size="5" color="red"><s:property value="age" /></FONT>   
  30. <br>   
  31. YOUR BIRTHDAY:   
  32. <FONT size="5" color="red"><s:property value="birthday" /></FONT>   
  33. <br>   
  34. YOUR EMAIL:   
  35. <FONT size="5" color="red"><s:property value="Email" /></FONT>   
  36. <br>   
  37. YOUR URL:   
  38. <FONT size="5" color="red"><s:property value="url" /></FONT>   
  39. <br>   
  40. YOUR PROGARAM:   
  41. <FONT size="5" color="red"><s:property value="program" /></FONT>   
  42. <br>   
  43. YOUR FAVOURITE COLOR:   
  44. <FONT size="5" color="red"><s:property value="color" /></FONT>   
  45. <br>   
  46. YOUR HIDDEN NAME   
  47. <FONT size="5" color="red"><s:property value="hiddenName" /></FONT>   
  48. <br>   
  49.   
  50. TREE:   
  51. <s:property value="child2" />   
  52.   
  53. </body>   
  54. </html>  
<%@ page language="java" c pageEncoding="GB2312"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" c> <title>login</title> </head> <body> YOUR USERNAME: <FONT size="5" color="red"><s:property value="username" /></FONT> <br> YOUR PASSWORD: <FONT size="5" color="red"><s:property value="password" /></FONT> <br> YOUR USERNAME: <FONT size="5" color="red"><s:property value="user.username" /></FONT> <br> YOUR PASSWORD: <FONT size="5" color="red"><s:property value="user.password" /></FONT> <br> YOUR NAME: <FONT size="5" color="red"><s:property value="name" /></FONT> <br> YOUR AGE: <FONT size="5" color="red"><s:property value="age" /></FONT> <br> YOUR BIRTHDAY: <FONT size="5" color="red"><s:property value="birthday" /></FONT> <br> YOUR EMAIL: <FONT size="5" color="red"><s:property value="Email" /></FONT> <br> YOUR URL: <FONT size="5" color="red"><s:property value="url" /></FONT> <br> YOUR PROGARAM: <FONT size="5" color="red"><s:property value="program" /></FONT> <br> YOUR FAVOURITE COLOR: <FONT size="5" color="red"><s:property value="color" /></FONT> <br> YOUR HIDDEN NAME <FONT size="5" color="red"><s:property value="hiddenName" /></FONT> <br> TREE: <s:property value="child2" /> </body> </html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值