struts2标签

package com.action;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.bean.Person;
import com.opensymphony.xwork2.ActionSupport;

public class TestOGNL extends ActionSupport {

	private static final long serialVersionUID = 5422654139464281838L;
	
	private String testStr ;
	
	private Person person ;
	
	private List<Person> list ;
	
	private List<String> append1;
	
	private List<String> append2;
	
	private Map<String , String> map ;
	
	private String testGeneratorStr = "万事如意,四季安康,心想事成,生龙活虎";

	@Override
	public String execute() throws Exception {
		testStr = "测试字符串";
		person = new Person();
		person.setName("也是测试字符串");
		person.setAge(25);
		list = new ArrayList<Person>();
		for (int i = 0; i < 5; i++) {
			Person p = new Person();
			p.setAge(i * 10 + 5);
			p.setName(UUID.randomUUID().toString());
			list.add(p);
		}
		append1 = new ArrayList<String>();
		append2 = new ArrayList<String>();
		for (int i = 0; i < 5; i++) {
			append1.add("append1:" + (i + 1));
		}
		for (int i = 0; i < 5; i++) {
			append2.add("append2:" + (i + 1));
		}
		map = new HashMap<String,String>();
		for (int i = 0; i < 5; i++) {
			map.put("key" + (i + 1), UUID.randomUUID().toString());
		}
		return SUCCESS;
	}

	public String getTestStr() {
		return testStr;
	}

	public void setTestStr(String testStr) {
		this.testStr = testStr;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public List<Person> getList() {
		return list;
	}

	public void setList(List<Person> list) {
		this.list = list;
	}

	public List<String> getAppend1() {
		return append1;
	}

	public void setAppend1(List<String> append1) {
		this.append1 = append1;
	}

	public List<String> getAppend2() {
		return append2;
	}

	public void setAppend2(List<String> append2) {
		this.append2 = append2;
	}

	public Map<String, String> getMap() {
		return map;
	}

	public void setMap(Map<String, String> map) {
		this.map = map;
	}

	public String getTestGeneratorStr() {
		return testGeneratorStr;
	}

	public void setTestGeneratorStr(String testGeneratorStr) {
		this.testGeneratorStr = testGeneratorStr;
	}
	
	
}
 
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib uri="/struts-tags"  prefix="s"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
	<s:property value="testStr"/><hr />
	<s:property value="person.name"/><hr />
	<s:property value="person.age"/>
	<s:if test="person.age >= 10 and person.age <= 20">
		>=10 <= 20
	</s:if>
	<s:elseif test="person.age >= 20 and person.age <= 30">
		>=20 <= 30
	</s:elseif>
	<s:else>
		>= 30
	</s:else>
	<hr />
	
	<table border="1">
	<s:iterator value="list" status="st">
		<s:if test="#st.odd">
			<tr style="background-color:red">		
		</s:if>
		<s:else>
			<tr>
		</s:else>
			<td><s:property value="name" /></td>		
			<td><s:property value="age" /></td>		
		</tr>
	</s:iterator>
	</table>
	<hr />
	<!-- 这是append标签,用于将多个list合并成一个list , 其中id是新的集合的变量 -->
	<!-- s:property 中如果是单个元素(不是对象) , 则可以通过在s:iterator中指定id的方式输出 -->
	<s:append id="newList">
		<s:param value="append1"></s:param>
		<s:param value="append2"></s:param>
	</s:append>
	<s:iterator value="newList" id="ele">
		<s:property value="ele"/><br />		
	</s:iterator>
	<hr />
	s:property输出map<br />
	<s:iterator value="map">
		<s:property value="key"/> : <s:property value="value"/><br />
	</s:iterator>
	<hr />
	测试s:generator<br />
	<s:generator separator="," val="testGeneratorStr" id="">
		<s:iterator id="e">
			<s:property value="e"/><br />
		</s:iterator>
	</s:generator>
	<hr />
	
</body>
</html>
 

你可能感兴趣的:(html,bean,struts)