各种标签的使用,包括标签的每个属性尅自己去下载最新的官方文档去阅读学习
其中有控制标签,数据标签,UI标签等等
struts.xml
<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true"/>
<constant name="struts.ui.theme" value="simple"/>
<package name="tags" extends="struts-default">
<action name="tags" class="com.dqpi.eonline.tags.TagsAction">
<result>/tags.jsp</result>
</action>
</package>
</struts></span>
index.jsp
<span style="font-size:18px;"><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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>resultType.jsp</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>
<a href="tags?username=a&password=p">访问tags标签</a><br/>
</body>
</html>
</span>
include.jsp
<span style="font-size:18px;"><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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 '_include.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 JSP page. <br>
</body>
</html>
</span>
_include1.html
<span style="font-size:18px;"><!DOCTYPE html>
<html>
<head>
<title>_include1.html</title>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
This is my _include1 page. <br>
</body>
</html>
</span>
_include2.html
<span style="font-size:18px;"><!DOCTYPE html>
<html>
<head>
<title>_include2.html</title>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
中文<br>
</body>
</html>
</span>
tags.jsp
<span style="font-size:18px;"><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'ognl.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>
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/>'" escape="false"/><br/>
<hr/>
<!--name和id已经废弃通过设置scope来设置取值范围 -->
set设定adminName值(默认为request和ActionContext):<s:set var="adminName" value="username"/><br/>
set从request取值:<s:property value="#request.adminName"/><br/>
set从ActionContext取值:<s:property value="#adminName"/><br/>
set设定范围:<s:set name="adminPassword" value="password" scope="page"/><br/>
set从相应的范围取值:<%=pageContext.getAttribute("adminPassword") %><br/>
set设定var,范围为ActionContext:<s:set var="adminPassword" value="password"/><br/>
set使用#取值:<s:property value="#adminPassword"/><br/>
<hr/>
<%-- push:<s:set name="myDog" value="new com.dqpi.eonline.tags.Dog('xiaohuang')"/><br/>
push:<s:push value="#myDog">
<s:property value="name"/>
</s:push>
push:<s:property value="name"/>
<hr/> --%>
bean定义bean,并使用param来设定新的属性值
<s:bean name="com.dqpi.eonline.tags.Dog">
<s:param name="name" value="'dagou'"></s:param>
<s:property value="name"/>
<s:debug></s:debug>
</s:bean> <br/>
bean查看debug情况:
<s:bean name="com.dqpi.eonline.tags.Dog" var="myDog">
<s:param name="name" value="'dahaung'"></s:param>
</s:bean>
<s:property value="#myDog.name"/>
include _include1.html包含静态英文文件
<s:include value="/_include1.html"></s:include><br/>
include _include2.html包含静态中文文件
<s:include value="/_include2.html"></s:include><br/>
include _include1.html包含静态英文文件,说明%用法
<s:set var="incPage" value="'/_include1.html'"></s:set>
<s:include value="%{#incPage}"></s:include><br/>
<hr/>
if elseif else:
age=<s:property value="#parameters.age[0]"/><br/>
<s:if test="#parameters.age[0] < 0">wrong age!</s:if>
<s:elseif test="#parameters.age[0] < 20">too young!</s:elseif><br/>
<s:if test="#parameters.aaa ==null">null</s:if>
<hr/>
遍历集合:<s:iterator value="{1,2,3}">
<s:property/> |
</s:iterator><br/>
自定义变量:
<s:iterator value="{'aaa','bbb','ccc'}" var="x">
<s:property value="#x.toUpperCase()"/>
</s:iterator><br/>
使用status:
<s:iterator value="{'aaa','bbb','ccc'}" var="x">
<s:property/> |
遍历过的元素总数:<s:property value="#status.count"/>|<br/>
遍历过的元素索引:<s:property value="#status.index"/>|<br/>
当前是偶数?:<s:property value="#status.even"/>|<br/>
当前是奇数?:<s:property value="#status.odd"/>|<br/>
是第一个元素吗?:<s:property value="#status.first"/>|<br/>
是最后一个元素吗?:<s:property value="#status.last"/><br/>
</s:iterator>
<s:iterator value="#{1:'a',2:'b',3:'c'}" >
<s:property value="key"/>|<s:property value="value"/>
</s:iterator><br/>
<s:iterator value="#{1:'a',2:'b',3:'c'}" var="x">
<s:property value="#x.key"/>|<s:property value="#x.value"/>
</s:iterator><br/>
<%-- <s:fielderror fieldName="fielderror.test" theme="simple"></s:fielderror> --%>
<s:debug></s:debug>
</body>
</html>
</span>