Struts2的标签三大类是什么?
Struts2 标签
一 Struts标签的简介:
Struts2 自己封装了一套标签,比 JSTL 强大,而且与 Struts2 中的其他功能无缝结合。 当然 Strust2 标签的内容很多,随着版本的升级,标签和属性越来越多。我们要掌握好核心标签及了解其他标签; 根据功能可以分为:数据标签,控制标签,界面标签,其他标签;(其实如果学过标准标签库stl基本上这部分内容简单的一批)
二 Struts2 数据标签
Property 标签:输出 OGNL 表达式的值; 取值
<% request.setAttribute("name","<font color='red' >张三</font>"); %>
<body>
<h1>property</h1>
<s:property value="#request.name"/><br/>
<s:property value="#request.name2" default="某某"/><br/>
<s:property value="#request.name" escapeHtml="false"/><br/>
</body>
Set 标签:设置变量;
<h1>set标签</h1>
<s:set var="i" value="1"/><br/>
i= <s:property value="#i"/><br/>
<s:set var="a" value="'action的值类似于值栈(value-stack)'" scope="action"></s:set>
<s:set var="p" value="'page的值'" scope="page"></s:set>
<s:set var="re" value="'request值'" scope="request"></s:set>
<s:set var="se" value="'session值'" scope="session"></s:set>
<s:set var="app" value="'application值'" scope="application"></s:set>
action:<s:property value="#a"/><br/>
page:<s:property value="#attr.p"/><br/>
request:<s:property value="#request.re"/><br/>
session:<s:property value="#session.se"/><br/>
application:<s:property value="#application.app"/><br/>
Bean 标签:定义 javaBean 对象;
<h1>bean标签</h1>
<s:bean name="com.java1234.model.Student" var="student">
<s:param name="name" value="'张三'"></s:param>
<s:param name="age" value="18"></s:param>
</s:bean>
name:<s:property value="#student.name"/><br/>
age:<s:property value="#student.age"/><br/>
Date 标签:日期标签;
<% request.setAttribute("date", new Date()); %>
<body>
<h1>Date标签</h1>
日期: ${date }<br/>
日期: <s:date name="#request.date" format="yyyy-MM-dd"/>
</body>
Debug 标签:调试标签;
<h1>Debug标签</h1>
<s:debug></s:debug>
Url&a 标签:超链接标签;
<s:a action="hello" namespace="/forgroud" > <s:param name="name" value="'struts2'"></s:param> 链接a </s:a>
Include 标签:动态包含标签;
<s:include value="head.html"></s:include>
三 Struts2 控制标签
Ifelse 标签:条件判断标签;
<% int age=11; request.setAttribute("age", age); %>
<body>
<h1>if else标签</h1>
年龄:<s:property value="#request.age"/>
<s:if test="#request.age<18">
小于18岁
</s:if>
<s:elseif test="#request.age<30">
大于18岁 小于30岁
</s:elseif>
<s:else>
大于30岁
</s:else>
</body>
Iterator 标签:遍历标签;
<%
List<Student>studentList=new ArrayList<Student>();
studentList.add(new Student(1,"张三",18));
studentList.add(new Student(2,"李四",19));
studentList.add(new Student(5,"王五",25));
request.setAttribute("studentList", studentList);
%>
<body>
<h1>iterator</h1>
<table border="1">
<tr>
<th>序号</th>
<th>学号</th>
<th>姓名</th>
<th>年龄</th>
</tr>
<s:iterator value="#request.studentList" var="sl" status="status">
<tr>
<td><s:property value="#status.index+1"/></td>
<td><s:property value="id"/></td>
<td><s:property value="name"/></td>
<td><s:property value="age"/></td>
</tr>
</s:iterator>
</table>
</body>
Append 标签:叠加标签;
<%
List<Student>studentList=new ArrayList<Student>();
List<Student>studentList1=new ArrayList<Student>();
studentList.add(new Student(1,"张三",18));
studentList.add(new Student(2,"李四",19));
studentList.add(new Student(5,"王五",25));
studentList1.add(new Student(6,"赵六",27));
studentList1.add(new Student(7,"小七",28));
request.setAttribute("studentList", studentList);
request.setAttribute("studentList1", studentList1);
%>
<body>
<s:append var="studentList2">
<s:param value="#request.studentList"></s:param>
<s:param value="#request.studentList1"></s:param>
</s:append>
<h1>iterator</h1>
<table border="1">
<tr>
<th>序号</th>
<th>学号</th>
<th>姓名</th>
<th>年龄</th>
</tr>
<s:iterator value="#request.studentList2" var="sl" status="status">
<tr>
<td><s:property value="#status.index+1"/></td>
<td><s:property value="id"/></td>
<td><s:property value="name"/></td>
<td><s:property value="age"/></td>
</tr>
</s:iterator>
</table>
</body>
Generator 标签:分隔标签;
<s:generator separator="," val="'张三,李四,王五'" var="nameList"></s:generator>
<s:iterator value="#nameList">
<s:property/>
</s:iterator>
Merge 标签:组合标签;
Sort 标签:排序标签;我们使用一个简单的例子学习一下:
Model:Student类:
public class Student {
private String name;
private int id;
private int age;
public Student() {
super();
// TODO Auto-generated constructor stub
}
public Student( int id, String name,int age) {
super();
this.name = name;
this.id = id;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
排序类:com.java1234.compator.MyComparator代码:
public class MyComparator implements Comparator<Student>{
public int compare(Student s1,Student s2){
if(s1.getAge()>s2.getAge()){
return 1;
}else if(s1.getAge()<s2.getAge()){
return -1;
}else{
return 0;
}
}
}
<%
List<Student>studentList=new ArrayList<Student>();
studentList.add(new Student(1,"张三",18));
studentList.add(new Student(2,"李四",19));
studentList.add(new Student(5,"王五",25));
studentList.add(new Student(6,"王五",17));
studentList.add(new Student(7,"王五",19));
request.setAttribute("studentList", studentList);
%>
<body>
<h1>iterator</h1>
<s:bean id="Mycomparator" name="com.java1234.compator.MyComparator"></s:bean>
<table border="1">
<tr>
<th>序号</th>
<th>学号</th>
<th>姓名</th>
<th>年龄</th>
</tr>
<s:sort comparator="#Mycomparator" source="#request.studentList">
<s:iterator status="status">
<tr>
<td><s:property value="#status.index+1"/></td>
<td><s:property value="id"/></td>
<td><s:property value="name"/></td>
<td><s:property value="age"/></td>
</tr>
</s:iterator>
</s:sort>
</table>
Subset 标签:截取标签;
<%
List<Student>studentList=new ArrayList<Student>();
studentList.add(new Student(1,"张三",18));
studentList.add(new Student(2,"李四",19));
studentList.add(new Student(5,"王五",25));
studentList.add(new Student(6,"赵六",28));
request.setAttribute("studentList", studentList);
%>
<body>
<h1>subset</h1>
<table border="1">
<tr>
<th>序号</th>
<th>学号</th>
<th>姓名</th>
<th>年龄</th>
</tr>
<s:subset source="#request.studentList" start="2" count="2">
<s:iterator status="status">
<tr>
<td><s:property value="#status.index+1"/></td>
<td><s:property value="id"/></td>
<td><s:property value="name"/></td>
<td><s:property value="age"/></td>
</tr>
</s:iterator>
</s:subset>
</table>
</body>
四 Strut2 界面标签
Form 标签:表单提交标签;
<s:form method="post" action="hello" namespace="/forgroud">提交内容</s:form>
Text 标签:文本标签;
用户名:<s:textfield name="name"></s:textfield>
密码:<s:password name="password"></s:password>
备注:<s:textarea name="desc"></s:textarea>
Radios 标签:单选标签;
性别单选框: <s:radio list="#{0:'男',1:'女' }" name="sex" value="0"></s:radio>
Checkboxlist 标签:复选框标签;
<s:checkboxlist list="#{0:'唱歌',1:'跳舞',2:'篮球' }"name="hobby" value="1"></s:checkboxlist>
Select 标签:下拉框标签;
下拉框: <s:select list="#{0:'跳舞',1:'篮球',2:'唱歌' }" name="bobby" value="0"></s:select>
Struts2的标签三大类是什么?的更多相关文章
- Struts2+Spring+Hibernate 三大框架的合并集成
这次来看看Struts2+Spring+Hibernate三大框架的整合应用,主要是Spring和Hibernate框架的整合,因为前边已经将Strtus2+Spring整合过了基本一样. 首先看一 ...
- Struts2之Struts2的标签库
前言: Struts2提供了大量的标签 ,用来帮助开发表现层页面,这些表现一方面解决了美观性的需求,因为它们具有html标签一样的外观,另一方面它们解决了功能性的需求, 因为它们具有jsp脚本一样的逻 ...
- 【Java EE 学习 36】【struts2】【struts2系统验证】【struts2 ognl值栈】【struts2 ongl标签】【struts2 UI标签】【struts2模型驱动和令牌机制】
一.struts2系统验证 1.基于struts2系统验证的方式实际上就是通过配置xml文件的方式达到验证的目的. 2.实际上系统校验的方法和手工校验的方法在底层的基本实现是相同的.但是使用系统校验的 ...
- Struts2常用标签
Struts2常用标签总结 一 介绍 1.Struts2的作用 Struts2标签库提供了主题.模板支持,极大地简化了视图页面的编写,而且,struts2的主题.模板都提供了很好的扩展性.实现了更好的 ...
- Struts2的标签库(五)——表单标签
Struts2的标签库(五) --表单标签 几个特殊的表单标签的使用: 1.checkboxlist标签 该标签用于创建多个复选框,用于同时生成多个<input type="check ...
- Struts2的标签库(四)——数据标签
Struts2的标签库(四) --数据标签 1.action标签 该标签用于在jsp页面直接调用一个Action,通过指定executeResult参数,还可以将Action的处理结果包含到此页面中来 ...
- Struts2的标签库(三)——控制标签
Struts2的标签库(三) --控制标签 1.if/elseif/else标签 用于分支控制,取代JSP中的if语句,根据一个boolean(test属性的值)值判断是否进行下一步运算或者输出等. ...
- Struts2的标签库(一)——使用Struts2的标签库
Struts2的标签库(一) --使用Struts2的标签库 1.Struts2的标签库其实就是一个自定义的标签库,所以它也有它的标签处理类和标签库定义文件: 2.和所有自定义标签一样,我们可以找到S ...
- JavaWeb框架_Struts2_(五)----->Struts2的标签库
1. Struts2的标签库 1.1 Struts2标签库概述 Struts2的标签库可以分为以下3类:用户界面标签.非用户界面标签.AJAX标签; 2.1.1 Struts2标签库的分类和使用 1 ...
随机推荐
- QT+常用控件_Line Edit
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QDebug> #incl ...
- [NOI2010]海拔——最小割+对偶图
题目链接 SOLUTION 想一下最优情况下肯定让平路或下坡尽量多,于是不难想到这样构图:包括左上角的一部分全部为\(0\),包括右下角的一部分全部为\(1\),于是现在问题转化为求那个分界线是什么. ...
- java上传、下载、删除ftp文件
一共三个类,一个工具类Ftputil.,一个实体类Kmconfig.一个测试类Test 下载地址:http://download.csdn.net/detail/myfmyfmyfmyf/669710 ...
- classList属性和className的区别
className的不方便之处: 在操作类名时,需要通过className属性添加,删除和替换类名.因为className中是一个字符串,所以即使只修改字符串一部分,也必须每次都设置整个字符串的值.( ...
- 学习笔记(_huaji_)
假如我没有见过太阳,我也许会忍受黑暗. 如果我知道自己会在哪里死去,我就永远都不去那儿.失败的经历,其实也有它的价值. 人的过失会带来错误,但要制造真正的灾难还得用计算机. 嘴角微微上扬已不复当年轻狂 ...
- uboot顶层mkconfig分析
GNU make:http://www.gnu.org/software/make/manual/make.html#Rules 为了便于理解把uboot中的Makefile配置部分弄出来便于理解,这 ...
- LeetCode(150) Evaluate Reverse Polish Notation
题目 Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, ...
- LeetCode(96) Unique Binary Search Trees
题目 Given n, how many structurally unique BST's (binary search trees) that store values 1-n? For exam ...
- 【C#】【数据结构】002-线性表:单链表
C#数据结构:单链表 1.自定义单链表结构: 单链节点类 using System.Collections; using System.Collections.Generic; using Unity ...
- HttpServlet RequestDispatcher sendredirect和forward
Servlet的框架是由两个Java包组成:javax.servlet和javax.servlet.http. 在javax.servlet包中定义了所有的Servlet类都必须实现或扩展的的通用接口 ...