struts tags小结
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学习
-
property:
-
property 取值为字符串:
-
property 设定默认值:
-
property 设定HTML:
-
set 设定adminName值(默认为request 和 ActionContext):
-
set 从request取值:
-
set 从ActionContext取值: <%--
-
set 设定范围:
-
set 从相应范围取值: <%=pageContext.getAttribute("adminPassword") %> --%>
-
set 设定var,范围为ActionContext:
-
set 使用#取值:
-
set 从相应范围取值:
<%--
-
push:
-
push:
-
push: --%>
-
bean 定义bean,并使用param来设定新的属性值:
-
bean 查看debug情况: 拿出值:
-
include _include1.html 包含静态英文文件
-
include _include2.html 包含静态中文文件
-
include _include1.html 包含静态英文文件,说明%用法,%{}将里面的内容强制转换成0ngl表达式
-
if elseif else: age =
wrong age! too young! yeah!
null
-
遍历集合:
| -
自定义变量:
| -
使用status:
| 遍历过的元素总数: | 遍历过的元素索引: | 当前是偶数?: | 当前是奇数?: | 是第一个元素吗?: | 是最后一个元素吗?: -
|
-
|
_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 中文