作者在 2010-12-27 11:03:47 发布以下内容
1.TestTableAction.java
package action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionSupport;
import data.DataDao;
import data.TestDataDao;
import data.TestDataDao;
public class TestTableAction extends ActionSupport {
private String tableNum;
private List<DataDao> datadaoList;
private String tableNum;
private List<DataDao> datadaoList;
final String HTTP_REQUEST = org.apache.struts2.StrutsStatics.HTTP_REQUEST;
public String getTableNum() {
return tableNum;
}
public String getTableNum() {
return tableNum;
}
public void setTableNum(String tableNum) {
this.tableNum = tableNum;
}
public String execute() {
ActionContext ctx = ActionContext.getContext();
HttpServletRequest req = (HttpServletRequest) ctx.get(HTTP_REQUEST);
Map session = ctx.getSession();
tableNum = req.getParameter("num");
datadaoList = new ArrayList<DataDao>();
DataDao dataDao1 = new DataDao();
dataDao1.setNoOfDate(1);
List<TestDataDao> testDataList1 = new ArrayList<TestDataDao>();
TestDataDao t1 = new TestDataDao();
t1.setColor("yellow");
t1.setSize(100);
TestDataDao t2 = new TestDataDao();
t2.setColor("red");
t2.setSize(200);
TestDataDao t3 = new TestDataDao();
t3.setColor("blue");
t3.setSize(300);
testDataList1.add(t1);
testDataList1.add(t2);
testDataList1.add(t3);
dataDao1.setTestData(testDataList1);
DataDao dataDao2 = new DataDao();
dataDao2.setNoOfDate(2);
List<TestDataDao> testDataList2 = new ArrayList<TestDataDao>();
TestDataDao t4 = new TestDataDao();
t4.setColor("black");
t4.setSize(400);
TestDataDao t5 = new TestDataDao();
t5.setColor("green");
t5.setSize(500);
testDataList2.add(t4);
testDataList2.add(t5);
dataDao2.setTestData(testDataList2);
datadaoList.add(dataDao1);
datadaoList.add(dataDao2);
session.put("tables", tableNum);
session.put("datadaoList", datadaoList);
return SUCCESS;
}
this.tableNum = tableNum;
}
public String execute() {
ActionContext ctx = ActionContext.getContext();
HttpServletRequest req = (HttpServletRequest) ctx.get(HTTP_REQUEST);
Map session = ctx.getSession();
tableNum = req.getParameter("num");
datadaoList = new ArrayList<DataDao>();
DataDao dataDao1 = new DataDao();
dataDao1.setNoOfDate(1);
List<TestDataDao> testDataList1 = new ArrayList<TestDataDao>();
TestDataDao t1 = new TestDataDao();
t1.setColor("yellow");
t1.setSize(100);
TestDataDao t2 = new TestDataDao();
t2.setColor("red");
t2.setSize(200);
TestDataDao t3 = new TestDataDao();
t3.setColor("blue");
t3.setSize(300);
testDataList1.add(t1);
testDataList1.add(t2);
testDataList1.add(t3);
dataDao1.setTestData(testDataList1);
DataDao dataDao2 = new DataDao();
dataDao2.setNoOfDate(2);
List<TestDataDao> testDataList2 = new ArrayList<TestDataDao>();
TestDataDao t4 = new TestDataDao();
t4.setColor("black");
t4.setSize(400);
TestDataDao t5 = new TestDataDao();
t5.setColor("green");
t5.setSize(500);
testDataList2.add(t4);
testDataList2.add(t5);
dataDao2.setTestData(testDataList2);
datadaoList.add(dataDao1);
datadaoList.add(dataDao2);
session.put("tables", tableNum);
session.put("datadaoList", datadaoList);
return SUCCESS;
}
public List<DataDao> getDatadaoList() {
return datadaoList;
}
return datadaoList;
}
public void setDatadaoList(List<DataDao> datadaoList) {
this.datadaoList = datadaoList;
}
this.datadaoList = datadaoList;
}
}
2.table.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*" %>
<%@ page import="data.DataDao"%>
<%@ page import="data.TestDataDao"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!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=ISO-8859-1">
<title>Insert title here</title>
<style>
table td {width:100px;}
</style>
</head>
<body>
<% int tables = Integer.parseInt((String)session.getAttribute("tables")); %>
<%
List<DataDao> dataDaoList = (List)session.getAttribute("datadaoList");
%>
<%for (int j = 0; j < tables; j++) { %>
<table border="1" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td></td>
<td>Color</td>
<td>Size</td>
</tr>
</thead>
<tbody>
<%
Iterator outerIt = dataDaoList.iterator();
while(outerIt.hasNext()) {
DataDao dataDao = (DataDao)outerIt.next();
int noOfDate = dataDao.getNoOfDate();
List testDataDaoList = dataDao.getTestData();
int innerSize = testDataDaoList.size();
int counter = 0;
Iterator innerIt = testDataDaoList.iterator();
while(innerIt.hasNext()) {
TestDataDao testDataDao = (TestDataDao)innerIt.next();
%>
<tr>
<%if (counter == 0) {%>
<td rowspan="<%=innerSize %>"><%=noOfDate %></td>
<% } %>
<td><%=testDataDao.getColor() %></td>
<td><%=testDataDao.getSize() %></td>
<%counter++; %>
</tr>
<%
}
}
%>
</tbody>
</table>
<%} %>
</body>
</html>
pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*" %>
<%@ page import="data.DataDao"%>
<%@ page import="data.TestDataDao"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!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=ISO-8859-1">
<title>Insert title here</title>
<style>
table td {width:100px;}
</style>
</head>
<body>
<% int tables = Integer.parseInt((String)session.getAttribute("tables")); %>
<%
List<DataDao> dataDaoList = (List)session.getAttribute("datadaoList");
%>
<%for (int j = 0; j < tables; j++) { %>
<table border="1" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td></td>
<td>Color</td>
<td>Size</td>
</tr>
</thead>
<tbody>
<%
Iterator outerIt = dataDaoList.iterator();
while(outerIt.hasNext()) {
DataDao dataDao = (DataDao)outerIt.next();
int noOfDate = dataDao.getNoOfDate();
List testDataDaoList = dataDao.getTestData();
int innerSize = testDataDaoList.size();
int counter = 0;
Iterator innerIt = testDataDaoList.iterator();
while(innerIt.hasNext()) {
TestDataDao testDataDao = (TestDataDao)innerIt.next();
%>
<tr>
<%if (counter == 0) {%>
<td rowspan="<%=innerSize %>"><%=noOfDate %></td>
<% } %>
<td><%=testDataDao.getColor() %></td>
<td><%=testDataDao.getSize() %></td>
<%counter++; %>
</tr>
<%
}
}
%>
</tbody>
</table>
<%} %>
</body>
</html>
3.select.html
<!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>
<script src="/test/js/jquery.js"></script>
<script>
$(document).ready(function() {
$('#s1').change(function() {
if ($('#s1').val() == 'yes') {
$('#s2').show();
} else {
$('#s2').hide();
}
});
$('#go').click(function() {
var param = $('#s3').val();
var url = '/test/action/testTable.action?num=' + param;
//location.href = url;
window.open(url);
});
});
</script>
<style>
td {width:80px;}
td select {width:70px;}
</style>
</head>
<body>
<table>
<tr>
<td>
<select id="s1">
<option value="yes">show</option>
<option value="no">hide</option>
</select>
</td>
<td>
<select id="s2">
<option value="yes">show</option>
<option value="no">hide</option>
</select>
</td>
<td>
<select id="s3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td>
<td>
<input type="button" value="submit" id="go" />
</td>
</tr>
</table>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="/test/js/jquery.js"></script>
<script>
$(document).ready(function() {
$('#s1').change(function() {
if ($('#s1').val() == 'yes') {
$('#s2').show();
} else {
$('#s2').hide();
}
});
$('#go').click(function() {
var param = $('#s3').val();
var url = '/test/action/testTable.action?num=' + param;
//location.href = url;
window.open(url);
});
});
</script>
<style>
td {width:80px;}
td select {width:70px;}
</style>
</head>
<body>
<table>
<tr>
<td>
<select id="s1">
<option value="yes">show</option>
<option value="no">hide</option>
</select>
</td>
<td>
<select id="s2">
<option value="yes">show</option>
<option value="no">hide</option>
</select>
</td>
<td>
<select id="s3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td>
<td>
<input type="button" value="submit" id="go" />
</td>
</tr>
</table>
</body>
</html>