jsp:
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<%@page import="contest.entity.Team" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>团队报名信息</title>
<style>
body
{
background-color:#b0c4de;
}
table{
border="1";
align="center";
cellpadding="0";
cellspacing="1";
bgcolor="#666666";
}
</style>
</head>
<body>
<%@include file="teamBar.jsp"%>
<h1 align="center">我的团队报名信息</h1>
<table >
<c:forEach items="${requestScope.list}" var="t">
<tr> <td>编号</td><td>${t.getId()}</td></tr>
<tr> <td>房间类型</td><td>${t.getName()}</td></tr>
<tr> <td>面积</td><td>${t.getTea1()}</td></tr>
<tr> <td>容纳人数</td><td>${t.getTea2()}</td></tr>
<tr> <td>价格</td><td>${t.getStuid0()}</td></tr>
<tr> <td>空调</td><td>${t.getStuid1()}</td></tr>
<tr> <td>电视机</td><td>${t.getStuid2()}</td></tr>
<tr> <td>网络</td><td>${t.getCheckteam()}</td></tr>
</c:forEach>
</table>
</body>
</html>
dao:
package contest.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import contest.dbutil.SQLHelper;
import contest.entity.Team;
public class teamDao {
public ArrayList<Team> info(Team t){
ArrayList<Team> list=new ArrayList<Team>();
String sql="select team_name,team_teacher1,team_teacher2,stu_id0,stu_id1,stu_id2,checkteam from team where team_id like '%"+t.getId()+"%'";
ResultSet rs = null;
Connection conn = (Connection) SQLHelper.getConnection();
PreparedStatement prep = null;
try {
prep = (PreparedStatement) conn.prepareStatement(sql);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
rs = prep.executeQuery();
while(rs.next()){
Team c=new Team();
c.setName(rs.getString(1));
c.setTea1(rs.getString(2));
c.setTea2(rs.getString(3));
c.setStuid0(rs.getString(4));
c.setStuid1(rs.getString(5));
c.setStuid2(rs.getString(6));
c.setCheckteam(rs.getString(7));
list.add(c);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return list;
}
}
servlet:
package contest.servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import contest.dao.teamDao;
import contest.entity.Team;
/**
* Servlet implementation class informationServlet
*/
@WebServlet("/main/team/informationServlet")
public class informationServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public informationServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String id="1001";
Team t=new Team();
t.setId(id);
teamDao teamdao = new teamDao();
List<Team> list = teamdao.info(t);
for(int i=0;i<list.size();i++) {
System.out.println(list.get(i));
}
response.setContentType("text/html;charset=utf-8");
request.setAttribute("list", list);
System.out.println(list);
request.getRequestDispatcher("information.jsp").forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
错误结果:
改了一天了,就是不显示QAQ
刚刚查了一遍,后台没问题,是前台有问题,但不知道问题出在哪里