如何将链表从servlet传递到另一个servlet?当我运行时,它在listLeagues servlet中显示nul



addLeagueServlet.java

    String leagueName = request.getParameter("name");
    int leagueYear = Integer.parseInt(request.getParameter("yearleague"));
    String leagueSeason = request.getParameter("season");
    League league = new League(leagueYear, leagueSeason, leagueName);
    leagueList.add(new League(leagueYear, leagueSeason, leagueName));
    request.setAttribute("leagueList", leagueList);
    out.print("League successfully added!<br>");
    out.print("<a href='Landing.jsp'>Home</a>");

listLeagues.java

    Iterator iter = ((LinkedList)request.getAttribute("leaguelist")).iterator();
    League league = (League)iter.next();
    while(iter.hasNext())
    out.print(league.getName());

因此,当我单击jsp中的Listtheleages链接时,它会显示null指针异常。请告诉我如何将linkedlist从addleaguelist传递到listleaguess servlet。谢谢

在代码中键入。已将属性添加为"leagueList"。正在尝试以"leagueList"检索。

相关内容

  • 没有找到相关文章

最新更新