<%@page import="java.util.ArrayList"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="java.util.*" %> <%@ page import="java.sql.Timestamp" %> <%@page import="model.User" %> <%@ taglib prefix="s" uri="/struts-tags" %> <%-- <jsp:forward page="index.action"/> --%> <%--<%response.sendRedirect("index.action"); %> --%> <%pageContext.setAttribute("pageContextAttr", "0"); %> <%request.setAttribute("requestAttr", "1"); %> <%session.setAttribute("sessionAttr", "2"); %> <%application.setAttribute("applicationAttr", "3"); %> <html> <head></head> <body> <hr> 通过Struts2标签从值栈中获取值。<br/> <s:property value="#attr.pageContextAttr" /><br/> <s:property value="#request.requestAttr" /><br/> <s:property value="#session.sessionAttr" /><br/> <s:property value="#application.applicationAttr"/><br/> 通过EL表达式从值栈中获取值。<br/> ${attr.pageContextAttr}<br/> ${request.requestAttr}<br/> ${session.sessionAttr}<br/> ${application.applicationAttr} <hr> 调用静态方法和静态字段 <s:property value="@model.CallStaticMethodAndField@staticMethod()" /> <s:property value="@model.CallStaticMethodAndField@staticField" /> <hr/> set标签 <s:set var="i" value="100" /> <s:set var="i" value="100+#i" /> x:<s:property value="#i" /> <hr> push标签 <s:push value="#request"> <s:property value="requestAttr" /> </s:push> <hr> bean标签 <s:bean name="model.User" var="user"> <s:param name="name" value="'张野'"/><!--注意单引号! --> <s:param name="password" value="123"/> </s:bean> <s:property value="#user.name" /> ${user.password } <hr> date标签 <% Timestamp t = Timestamp.valueOf("2014-10-10 00:00:00"); Date d = new Date(t.getTime()); request.setAttribute("time", d); %> 时间:<s:date name="#request.time" format="yyyy-MM-dd"/> 时间差:<s:date name="#request.time" format="yyyy-MM-dd" nice="true"/> <hr/> debug标签: <s:debug></s:debug> <hr/> url标签 <s:url action="index.action" id="test"> </s:url> <a href="%{test}">登录</a> <hr/> include标签(动态包含)<br/> <s:include value="includetest.jsp"> <s:param name="data" value="'aaabbbccc'"></s:param> </s:include> <hr/> if、elseif、else标签<br/> <s:set name="y" value="12"></s:set> <s:if test="#y>10"> 大于10 </s:if> <s:elseif test="#y=10"> 等于10 </s:elseif> <s:else> 小于10 </s:else> <hr/> iterator标签 <% List<User> users = new ArrayList<User>(); for(int i=0; i<10; i++) { User u = new User(); u.setName("张三"+i); u.setPassword(i*22+""); u.setUserId(i); users.add(u); } request.setAttribute("users", users); %> <table border="1" > <tr> <td>编号</td> <td>姓名</td> <td>密码</td> </tr> <s:iterator value="#request.users" var="user" status="state"> <tr <s:if test="#state.even"> bgcolor="red" </s:if> > <td> <s:property value="userId" /> </td> <td> <s:property value="name" /> </td> <td> <s:property value="password" /> </td> </tr> </s:iterator> </table> </body> </html>