Struts2 的struts 标签
实战
strutstags.jsp
<%@ 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 '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>
Struts2标签使用:<br/>
1:<!--<s:a href="/ognl.action" target="_blank">aaaaaaaaaaaa</s:a><br/>
2:action使用:<s:action name="ognl" executeResult="true"></s:action>--><br/>
3:set 使用:<s:set name="var_set" value="100"></s:set> 查看结果<s:property value="#var_set"/>
</body>
</html>
<%@ 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 'strutstags.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>
数据标签,展示标签:<br/>
1:set 使用:<s:set var="person_name" value="'100'"></s:set> 查看结果:<s:property value="#person_name"/><br/>
2:text 使用:<s:text name="i18n.label.greetings" >
<s:property/>
</s:text> <br/>
3:url 使用:<s:url ></s:url><br/>
4:bean 使用:<s:bean name="com.summary.model.TitesModel" var="author1">
<s:property value="#author1.author"/>
<s:property value="#author1.getReply_to()"/>
</s:bean><br/>
5:s:include 使用:<s:include value="/index.jsp"></s:include><br/>
6:s:fielderror 使用: <s:fielderror name="error_message"></s:fielderror><br/>
<hr/>
控制标签<br/>
<br/>
7:if elseif else使用:<br/>
<s:if test="#parameters.age[0] >= 22">你可以结婚了</s:if><br/>
<s:elseif test="#parameters.age[0] < 22 && #parameters.age[0]>1">你不可以结婚</s:elseif><br/>
<s:else>输入错误</s:else><br/>
8:iterator使用:
<br/>
<s:iterator value="{1,2,3,4,5,6,7,8,9,10}">
值:<s:property/>|
</s:iterator>
<br/>
循环自定义变量: <br/>
<s:iterator value="{'aaa','bbb','ccc','ddd','eee','fff','gggg'}" var="my_var">
值:<s:property value="#my_var.toUpperCase()"/>|
</s:iterator>
<br/>
dataInfoList数据的显示:
<s:iterator value="dataInfoList" var="user_list">
备注:<s:property value="#user_list.remark"/>
学校:<s:property value="#user_list.school"/> <br/> <!-- 此处使用;自定义变量名.属性名称 -->
</s:iterator>
<br/>
<s:iterator value="dataInfoList" var="user_list" status="status">
<s:property value="#user_list.school"/>
统计当前数据记录总数:<s:property value="#status.count"/><br/>
</s:iterator>
循环键值:#{中间放入变量数组和集合} 定义Map为什么需要加"#"号<br/>
<!--
<s:iterator value="#{1:'a'}" >
值:<s:property value="key"/>|<br/>
</s:iterator>
-->
<br/>
<s:debug></s:debug>
</body>
</html>
struts.xml
<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
<package name="default" namespace="/" extends="struts-default">
<action name="ognl" class="com.struts2.action.OGNLController">
<result>/ognl.jsp</result>
</action>
<action name="strutstags" class="com.struts2.action.OGNLController">
<result>/strutstags.jsp</result>
</action>
</package>
分享到:
相关推荐
struts2 WebWork 2 标签 tags API 参考文档 参考手册
自己制作的struts2 tags,包括了struts2的所有标准标签。 格式是chm的,希望能对大家有所帮助.
struts2的标签使用的api,也是在网上下载的,挺好的
struts2-tags-API.rar
struts-tags.tld struts-tags.tldstruts-tags.tld struts-tags.tld struts-tags.tld
struts2 中tags.tld文件,共享使用
struts Tags
struts2-tags-API 轻松学习tags标签
Struts2案例翻译篇-Struts2 Tags Struts2案例翻译篇-HelloWorld
Eclipse使用struts2标签库tld文件
通过struts2 自定义标签实例,可以用这个对项目中的实现自定义标签。从而减少代码。
struts2标签详细帮助文档,介绍的很详细,每个标签后都有例子!
包含三个chm文档:struts2教程,标签tags详解,API
struts2 例子 struts.xml基本配置 页面跳转
In this tutorial we'll explore some of the other Struts 2 form controls. In our previous tutorials that explained how to use Struts 2 forms (Processing Forms, Form Validation, and Message Resource ...
struts-tags帮助文档真的很实用,平时做项目肯定少不了它!
struts2-tags-API帮助文档
Struts2-Tags_struts2标签用法