ITeye博客

struts tags小结

netxdiy · 2011-03-20 10:47 · struts2 · 企业架构 · HTML · Struts · XML · JSP · Bean · Markdown

struts.xml /tags.jsp TagsAction.java package com.bjsxt.struts2.tags; import com.opensymphony.xwork2.ActionSupport; public class TagsAction extends ActionSupport { private String password; private String username; public TagsAction() { } public String execute() { this.addFieldError("fielderror.test", "wrong!"); return SUCCESS; } public String getPassword() { return password; } public String getUsername() { return username; } public void setPassword(String password) { this.password = password; } public void setUsername(String username) { this.username = username; } } User.java package com.bjsxt.struts2.tags; public class User { private int age = 8; public User() { } public User(int age) { super(); this.age = age; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "user" + age; } } Dog.java package com.bjsxt.struts2.tags; public class Dog { private String name; public Dog() { } public Dog(String name) { super(); this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "dog: " + name; } } S.java package com.bjsxt.struts2.tags; public class S { public static String STR = "STATIC STRING"; public static String s() { return "static method"; } } index.jsp <%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <% String contextPath = request.getContextPath(); %> Insert title here 访问属性 tags tags.jsp <%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <%@ taglib uri="/struts-tags" prefix="s" %> Struts-Tags学习

  1. property:

  2. property 取值为字符串:

  3. property 设定默认值:

  4. property 设定HTML:


  5. set 设定adminName值(默认为request 和 ActionContext):

  6. set 从request取值:

  7. set 从ActionContext取值: <%--

  8. set 设定范围:

  9. set 从相应范围取值: <%=pageContext.getAttribute("adminPassword") %> --%>

  10. set 设定var,范围为ActionContext:

  11. set 使用#取值:

  12. set 从相应范围取值:


    <%--

  13. push:

  14. push:

  15. push: --%>


  16. bean 定义bean,并使用param来设定新的属性值:

  17. bean 查看debug情况: 拿出值:


  18. include _include1.html 包含静态英文文件

  19. include _include2.html 包含静态中文文件

  20. include _include1.html 包含静态英文文件,说明%用法,%{}将里面的内容强制转换成0ngl表达式


  21. if elseif else: age =
    wrong age! too young! yeah!
    null


  22. 遍历集合:
    |

  23. 自定义变量:
    |

  24. 使用status:
    | 遍历过的元素总数: | 遍历过的元素索引: | 当前是偶数?: | 当前是奇数?: | 是第一个元素吗?: | 是最后一个元素吗?:

  25. |

  26. |

_include.jsp <%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <%@ taglib uri="/struts-tags" prefix="s" %> _include params :
使用property取参数:p1=
使用property取参数:p2=
使用property取参数:p3=
_include1.html _include1.html This is my _include1 page.
_include2.html _include1.html 中文

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。