在jsp中使用Struts2的标签
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix = "s" uri="/struts-tags"%>
<%@taglib prefix="sx" uri="/struts-dojo-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'success.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>
<h3>访问数组中的元素、求数组中元素的个数</h3>
<s:set var="list" value="{'李冰冰','刘诗诗','杨幂','范冰冰'}"> </s:set>
<br>
<s:property value="#list[0]"/><br>
<s:property value="#list.size()"/>或
<s:property value="#list.size"/>
<h3>访问map中的元素,求map中元素的个数</h3>
<s:set var ="map" value="#{'k1':'v1',2:'v2',3:'v3'}"></s:set>
<br>
<s:property value="#map"/><br>
<s:property value="#map.size"/><br>
求出所有的key的值<br>
<s:property value="#map.keys"/><br>
求出所有的value的值<br>
<s:property value="#map.values"/><br>
根据key值,找对应的value<br>
<s:property value="#map.k1"/> 或
<s:property value="#map['k1']"/>
<h3>使用ognl调用方法/属性</h3>
使用ognl调用静态方法<br>
<s:property value="@java.lang.System@currentTimeMillis()"/>
使用ognl调用静态变量<br>
<s:property value="@java.lang.Math@PI"/>
使用ognl调用一般方法<br>
<s:property value="new java.util.Date().getTime()"/>
<h3>struts2标签中if语句对应java中的if</h3>
<s:set var="county" value="2"></s:set>
<s:if test="#county==1">美国</s:if>
<s:if test="#county==2">法国</s:if>
<s:if test="#county==3">英国</s:if>
<h3>迭代/遍历数组/集合中的元素</h3>
<s:set var="list1" value="{'蔡妍','全慧彬',' 张英兰',' 金泰熙',' 成宥利','韩佳人'}"></s:set>
<s:property value="#list1"/>
<s:if test="#list1!=null&& #list1.size()>0">
<ul>
<s:iterator value="#list1" var="user">
<li>
<s:property value="#user"/>或${user}
</li>
</s:iterator>
</ul>
</s:if>
<h3>对map迭代</h3>
<s:set var="map1" value="#{1:'v1','k2':'v2','k3':3}">
<s:if test="#map1!=null&&#map1.size()>0">
<ul>
<s:iterator value="#map1" var="mapIndex">
<li>
<s:property value="#mapIndex.key"/>
<s:property value="#mapIndex.value"/>
</li>
</s:iterator>
</ul>
</s:if>
</s:set>
<h3>struts2中时间的标签</h3>
<s:date name="new java.util.Date()" format="yyyy/MM/dd"/>
<sx:datetimepicker></sx:datetimepicker>
<s:debug></s:debug>
</body></html>