从简单的类中获取jsp页面中的(对象)团队的空列表

时间:2017-03-20 21:35:41

标签: java jsp servlets java-ee

我有一个jsp页面,其中我试图获取jsp中的团队列表(类对象)以显示有关团队的一些数据,但问题是在jsp上找到我的列表是空的,我不知道为什么它是空的,我试图在互联网上搜索它但找不到解决方案,我也调试了我的jsp页面,找到了空列表。

这是我的jsp代码

`<%@include file="index.html" %>
<%@page import="java.util.List,java.util.ArrayList"%>
<%@page import="Models.Team" %>
<%@page import="Controller.HockeyLeagueInitialization"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<% 
HockeyLeagueInitialization hli = new HockeyLeagueInitialization();
List<Team> teams = (ArrayList<Team>) hli.getTeamList();

%>



<ul class="dropdown-menu" role="menu" style="margin-left: 0%">
                        <% for (int i = 0; i < teams.size(); i++) {
                                Team currentTeam = teams.get(i);

                        %>
                        <li><a href="#"> <%= currentTeam.getTeamName()%></a></li>
                            <% }%>
                    </ul>`

这是我的函数返回列表

public List<Team> getTeamList() {

    String selectAllTeams = "select * from team;";
    List<Team> listOfTeam = new ArrayList<Team>();

    try {
        stmt = new DBInitialization().getStatement();
        ResultSet rs = stmt.executeQuery(selectAllTeams);

        while (rs.next()) {
            listOfTeam.add(new Team(rs.getInt("id"), rs.getString("name")));
        }

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return listOfTeam;
}

0 个答案:

没有答案