5,655
社区成员
发帖
与我相关
我的任务
分享
//Action类
package org.action;
import java.util.ArrayList;
import java.util.Map;
import org.model.Xsb;
import org.work.DBConn;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class ShowAction extends ActionSupport{
public String execute() throws Exception {
DBConn db=new DBConn();
ArrayList list = db.findLyInfo();
Map session=(Map)ActionContext.getContext().get("session");
session.put("list", list);
return this.SUCCESS;
}
}
//数据库中的查询方法
public ArrayList findLyInfo(){
try{
ArrayList list = new ArrayList();
pstmt=conn.prepareStatement("select * from [XSB]");
ResultSet rs=pstmt.executeQuery();
while(rs.next()){
Xsb xs=new Xsb();
xs.setXh(rs.getString(1));
xs.setXm(rs.getString(2));
xs.setXb(rs.getByte(3));
xs.setCssj(rs.getString(4));
xs.setZy(rs.getString(5));
xs.setBz(rs.getString(6));
list.add(xs);
}
return list;
}catch(Exception e){
e.printStackTrace();
return null;
}
}
//JSP页面显示
<%@ 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 'show.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 bgcolor = "#E3E3E3">
<center>
<table border="1">
<caption>学生信息</caption>
<tr>
<th>学号</th>
<th>姓名</th>
<th>性别</th>
<th>出生时间</th>
<th>专业</th>
<th>备注</th>
</tr>
<tr>
<s:iterator value="#request.list" id="l" >
<td><s:property value="#l.xh"></s:property></td>
<td><s:property value="#l.xm"></s:property></td>
<td><s:property value="#l.xb"></s:property></td>
<td><s:property value="#l.cssj"></s:property></td>
<td><s:property value="#l.zy"></s:property></td>
<td><s:property value="#l.bz"></s:property></td>
</s:iterator>
</tr>
</table>
</center>
</body>
</html>