Java Struts2 OGNL标签库之append拼接、merge拼接、subset筛选和sort排序

Struts2的表单标签可分为两种:Form表单本身和单个表单元素的标签。所有表单标签处理类都继承了UIBean类,UIBean包含了一些通用属性,分为3种。(1)模板相关属性、(2)JS相关属性、(3)通用属性。

如:注册表单例子

myform.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>


   
    Regist - Document
    
  
  
    
   		用户名:
   		密码:
   		性别:
   		爱好:
   		地区:
   		备注:
   		
   		
    
  

control.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>


      
    struts2标签库
	
  
  
  
  	
  	
  	无性别
  	
  	
    	
	
  	
  	
  	

append拼接结合List

append拼接结合Map

merge拼接结合List

Subset根据筛选器选择集合中的元素,筛选包含s的字符串

  

Sort排序

  

struts.xml




	
     
		
		
			/control.jsp
		
	


web.xml

  
  
     
    
    myform.jsp  
    
    
    struts2  
      
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  
      
    
    
    struts2  
    /*  
   

User.java

package top.k10000;
public class User {
	private String name;
	private String pass;
	private String sex;
	private String hoppy;
	private String prov;
	private String memo;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPass() {
		return pass;
	}
	public void setPass(String pass) {
		this.pass = pass;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getHoppy() {
		return hoppy;
	}
	public void setHoppy(String hoppy) {
		this.hoppy = hoppy;
	}
	public String getProv() {
		return prov;
	}
	public void setProv(String prov) {
		this.prov = prov;
	}
	public String getMemo() {
		return memo;
	}
	public void setMemo(String memo) {
		this.memo = memo;
	}	
}

RegistAction.java

package top.k10000;
import java.util.ArrayList;
import java.util.List;
import top.k10000.User;
import com.opensymphony.xwork2.ActionSupport;

public class RegistAction extends ActionSupport{
	private User user;
	private List list = new ArrayList();
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public List getList() {
		return list;
	}
	public void setList(List list) {
		this.list = list;
	}

	public String execute()throws Exception{
		User u1 = new User();
		u1.setName("s1");
		User u2 = new User();
		u2.setName("s2");
		User u3 = new User();
		u3.setName("s3");
		User u4 = new User();
		u4.setName("s4");
		User u5 = new User();
		u5.setName("s5");
		list.add(u1);
		list.add(u2);
		list.add(u3);
		list.add(u4);
		list.add(u5);
		return "success";
	}
}

ContainSDecider.java

package top.k10000;
import org.apache.struts2.util.SubsetIteratorFilter.Decider;

public class ContainSDecider implements Decider{
	@Override
	public boolean decide(Object element) throws Exception {
		String str = (String)element;
		return str.contains("s");
	}
	
}

TestComparator.java

package top.k10000;
import java.util.Comparator;

public class TestComparator implements Comparator{
	@Override
	public int compare(Object o1, Object o2) {
		String s1 = (String)o1;
		String s2 = (String)o2;
		return s1.compareTo(s2);
	}

}

结果如下:

Java Struts2 OGNL标签库之append拼接、merge拼接、subset筛选和sort排序_第1张图片

你可能感兴趣的:(#,SSH古董框架,Java)