一、数据标签
1.property:输出ognl表达式的值
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
<%
//设置request范围的ognl值
request.setAttribute("name","张三");
%>
结果截图:
2.set标签:设置变量
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
结果:
3.Bean标签:定义JavaBean对象
Student.java
package com.java1234.model;
public class Student {
private int id;
private String name;
private int age;
public Student() {
super();
// TODO Auto-generated constructor stub
}
public Student(int id, String name, int age) {
super();
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
bean.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
结果:
4.Date:日期标签
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
<%
request.setAttribute("date",new Date());
%>
${date }
当前日期:
结果:
5.debug标签:调试标签
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
结果:
6.Url&a标签:超链接标签
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
超链接
超链接2
7.include:动态包含标签
inclde.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
二、控制标签
1.ifelse标签:条件判断
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
<%
int age=11;
request.setAttribute("age","age");
%>
年龄小于20岁
年龄等于20岁
年龄大于20岁
2.iterator标签:遍历标签
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.java1234.model.Student" %>
<%@ page import="java.util.*" %>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
<%
List studentList=new ArrayList();
studentList.add(new Student(1,"张三",10));
studentList.add(new Student(3,"李四",20));
studentList.add(new Student(5,"王五",30));
request.setAttribute("studentList",studentList);
%>
序号
编号
姓名
年龄
status属性:可选属性,该属性在迭代时会产生一个IteratorStatus对象,该对象可以判断当前元素的位置,包含了以下属性方法:
int getCount(); 迭代元素个数
int getIndex(); 迭代元素当前索引
boolean getFirst(); 是否为第一个
boolean getEven(); 是否为偶
boolean getLast(); 是否最后一个
bolean getOdd(); 是否为奇
结果:顺序遍历:
3.append标签:叠加标签
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.java1234.model.Student" %>
<%@ page import="java.util.*" %>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
<%
//创建list对象,每个list里面有几个对象,使用叠加标签
List studentList1=new ArrayList();
List studentList2=new ArrayList();
studentList1.add(new Student(1,"张三",10));
studentList1.add(new Student(3,"李四",20));
studentList2.add(new Student(5,"王五",30));
studentList2.add(new Student(7,"赵六",40));
//将定义好的对象放到request中
request.setAttribute("studentList1",studentList1);
request.setAttribute("studentList2",studentList2);
%>
序号
编号
姓名
年龄
结果:按照叠加的顺序显示,先叠加哪个就先显示哪个
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.java1234.model.Student" %>
<%@ page import="java.util.*" %>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
<%
List studentList1=new ArrayList();
List studentList2=new ArrayList();
studentList1.add(new Student(1,"张三",10));
studentList1.add(new Student(3,"李四",20));
studentList2.add(new Student(5,"王五",30));
studentList2.add(new Student(7,"赵六",40));
request.setAttribute("studentList1",studentList1);
request.setAttribute("studentList2",studentList2);
%>
序号
编号
姓名
年龄
结果:不按顺序的排列
MyComparator.java
Comparator接口实现排序查看
--------------------- 本文来自 高钙高铁 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/u010839723/article/details/44300943
在为对象数组进行排序时
对象排序:实现Comparable接口,重写其中的compareTo(T o)方法,在其中定义排序规则
list排序:实现Comparator接口,重写compare方法,定义排序规则
MyComparator .java
package com.java1234.comparator;
import java.util.Comparator;
import com.java1234.model.Student;
public class MyComparator implements Comparator{
//重写Comparator接口的compare方法实现对list的排序,年龄从小到大排序
public int compare(Student s1, Student s2) {
if(s1.getAge()>s2.getAge()){
return 1;
}else if(s1.getAge()
sort.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.java1234.model.Student" %>
<%@ page import="java.util.*" %>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
<%
List studentList1=new ArrayList();
studentList1.add(new Student(1,"张三",20));
studentList1.add(new Student(3,"李四",10));
studentList1.add(new Student(5,"王五",40));
studentList1.add(new Student(7,"赵六",30));
request.setAttribute("studentList1",studentList1);
%>
序号
编号
姓名
年龄
结果:年龄升序排序
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.java1234.model.Student" %>
<%@ page import="java.util.*" %>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
<%
List studentList1=new ArrayList();
studentList1.add(new Student(1,"张三",20));
studentList1.add(new Student(3,"李四",10));
studentList1.add(new Student(5,"王五",40));
studentList1.add(new Student(7,"赵六",30));
request.setAttribute("studentList1",studentList1);
%>
序号
编号
姓名
年龄
结果:
一、界面标签
Form
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
Text
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
用户名:
密码:
备注:
Radios
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
性别:
Checkboxlist
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
爱好:
Select下拉框
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
爱好:
一、其他的标签
1.updownselect
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
A
结果
2.optiontransferselect
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
Insert title here
结果:
转载于:https://my.oschina.net/u/3848699/blog/2209208