标签:
$用于i18n和struts2配置文件
#用于取得ActionContext的值
%将原本的文本属性解析为ognl,对于本来就是ognl的属性不起作用
struts.xml简单配置
<package name="tags" namespace="/" extends="struts-default"> <action name="tags" class="com.ouc.wkp.action.TagsAction"> <result>/tags.jsp</result> </action> </package>
package com.ouc.wkp.action; 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; } }
然后下面的jsp展示了struts标签的用法
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP ‘tags.jsp‘ starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> This is my tags.jsp <br> property: <s:property value="username" /> <br /> property取值为字符串: <s:property value="‘username‘" /> <br /> property设定默认值: <s:property value="admin" default="管理员" /> <br /> property设定HTML: <s:property value="‘<hr>‘" /> <br /> property设定HTML: <s:property value="‘<hr>‘" escape="false" /> <br /> <br /> set设定adminName值(默认为request和ActionContext): <s:set var="adminName" value="username"></s:set> <br /> set从request取值: <s:property value="#request.adminName" /> <br /> set从ActionContext取值: <s:property value="#adminName" /> <br /> set设定范围: <s:set var="adminPassword" value="password" scope="page"></s:set> <br /> set从相应范围取值:<%=pageContext.getAttribute("adminPassword")%><br /> set设定scope,范围为session: <s:set var="adminPassword" value="password" scope="session"></s:set> <br /> set使用#取值: <s:property value="#adminPassword" /> <br> set从相应范围取值: <s:property value="#session.adminPassword" /> <br /> <br /> bean定义bean,并使用param设定新的属性值 <s:bean name="com.ouc.wkp.model.Dog"> <s:param name="name" value="‘MZ‘"></s:param> <s:property value="name" /> <br /> </s:bean> bean 查看debug情况: <s:bean name="com.ouc.wkp.model.Dog" var="myDog"> <s:param name="name" value="‘oudy‘"></s:param> </s:bean> 拿出值: <s:property value="#myDog.name" /> <br /> <s:fielderror name="fielderror.test" theme="simple"></s:fielderror> <br /> if elseif else: age= <s:property value="#parameters.age[0]" /> <br /> <s:set var="age" value="#parameters.age[0]"></s:set> <s:if test="#age < 0">wrong age!</s:if> <s:elseif test="#parameters.age[0]<20">too young!</s:elseif> <s:else>yes!</s:else> <s:if test="#parameters.aaa==null">null</s:if> <s:debug></s:debug> <br /> 遍历集合 <br /> <s:iterator value="{1,2,3}"> <s:property />| </s:iterator> <br /> 自定义变量 <br /> <s:iterator value="{‘aaa‘,‘bbb‘,‘ccc‘}" var="x"> <s:property /> <s:property value="#x.toUpperCase()" /> </s:iterator> <br /> 使用status: <br /> <s:iterator value="{‘aaa‘,‘bbb‘,‘ccc‘}" status="status"> <s:property /> 遍历过的元素总数:<s:property value="#status.count" />| 遍历过的元素索引:<s:property value="#status.index" />| 当前是偶数?:<s:property value="#status.even" /> 当前是奇数?:<s:property value="#status.odd" /> 是第一个元素吗?:<s:property value="#status.first" /> 是最后一个元素吗?:<s:property value="#status.last" /> <br /> 遍历Map 方法1 <s:iterator value="#{1:‘a‘,2:‘b‘,3:‘c‘}"> <s:property value="key" />|<s:property value="value" /> <br /> </s:iterator> 方法2 <s:iterator value="#{1:‘a‘,2:‘b‘,3:‘c‘}" var="x"> <s:property value="#x.key" />|<s:property value="#x.value" /> <br /> </s:iterator> </s:iterator> </body> </html>
ui标签感觉不太实用
标签:
原文地址:http://www.cnblogs.com/wangkaipeng/p/5738520.html