Struts2标签

<%@ 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 'index.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>
	<ol>
		<li>set标签,设置一个变量 值为 name <s:set var="a" value="'name'"></s:set> </li>
		<li>取出上面的值为 name 变量: <s:property value="a"/> </li>
		<li>取出action中属性为 name 值: <s:property value="name"/> </li>
		
		<li>set标签,设置一个变量 值为 action中的name <s:set var="a" value="name" scope="session"></s:set> </li>
		<li>取出session中的变量a: <s:property value="#session.a"/> </li>
		<li>set标签,设置一个变量 值为 action中的name <s:set var="a" value="name" scope="request"></s:set> </li>
		<li>取出request中的变量a: <s:property value="#request.a"/> </li>
		
		<hr>
		遍历数组
		<s:iterator value="array" status="status">
			
			<s:property/>
				遍历过的元素总数:<s:property value="#status.count"/> |
				遍历过的元素索引:<s:property value="#status.index"/> |
				当前是偶数?:<s:property value="#status.even"/> |	
				当前是奇数?:<s:property value="#status.odd"/> |		
				是第一个元素吗?:<s:property value="#status.first"/> |
				是最后一个元素吗?:<s:property value="#status.last"/>			<br>
		</s:iterator>
		
		<hr>
		遍历listList String list = new ArrayList String();
		<s:iterator value="list">
			<br>
			<s:property/>
		</s:iterator>
		<hr>
		
		<hr>
		遍历listList [user] list = new ArrayList [user]();
		<s:iterator value="userList" >
			<br>
			<s:property value="name"/>
			<s:property value="pass"/>
		</s:iterator>
		<hr>
		遍历map;
		<s:iterator value="map" >
			<br>
			<s:property value="key"/>
			<s:property value="value"/>
		</s:iterator>
		<hr>
		遍历userMap;
		<s:iterator value="UserMap" var="m">
			<br>
			<s:property value="#m.key"/>
			<s:property value="#m.value.name"/>
		</s:iterator>
		<hr>
		
		
		select
		
		<s:select 
		list="userList" 
		listKey="pass" 
		listValue="name" 
		name="s1">
		
		</s:select>
		<s:set var="b" value="100"></s:set>
		<s:if test="b>100">b大于100</s:if>
		<s:elseif test="b<100">b小于100</s:elseif>
		<s:else>b=100</s:else>
	</ol>
	<s:debug></s:debug>
  </body>
</html>



 

package com.wepull.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.opensymphony.xwork2.ActionSupport;
import com.wepull.model.User;

public class TagsAction extends ActionSupport {
	public String name;
	
	private User user;
	public List<String> list = new ArrayList<String>();
	public Set<String> set = new HashSet<String>();
	public Map<Integer,String> map = new HashMap<Integer,String>();
	
	public Map<Integer,User> UserMap = new HashMap<Integer,User>();
	
	
	
	public List<User> userList = new ArrayList<User>();

	public String[] array = new String[5];
	
	@Override
	public String execute() throws Exception {
		for (int i = 0; i < 5; i++) {
			list.add("list"+i);
			set.add("set"+i);
			map.put(i, "map"+i);
			User u = new User();
			u.setName("user"+i);
			u.setPass(i);
			userList.add(u);
			array[i]="arr"+i;
		}
		User u = new User();
		u.setName("ww");
		u.setPass(123);
		
		User u2 = new User();
		u2.setName("456");
		u2.setPass(456);
		
		UserMap.put(1, u);
		UserMap.put(2, u2);
		
		return SUCCESS;
	}
	
	public String fun(){
		System.out.println("执行了 fun()");
		return SUCCESS;
	}
	
	
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

}

 

你可能感兴趣的:(html,jsp,cache,css,struts)