我有这段代码:
<%
ArrayList<Team> teams = Lists_DEO.getAllTeams();
for (int i = 0; i < teams.size(); i++){
Team curr = teams.get(i);
%>
<div class="team-item-box <% if (i%2 == 1) out.print("second");%>">
<a href="/FUF_League/UserGetTeam?teamID=<%=curr.getID()%>" class="left"><img src="<%= curr.getImageURL() %>" alt=""></a>
<a href="/FUF_League/UserGetTeam?teamID=<%=curr.getID()%>" class="watch-now"><%= curr.getName()%></a>
</div>
<%
}
%>
它完成了它的工作...(我已经检查了out.print,每个teamID都有其独特的价值);
在UserGetTeam(servlet)中的我有这个代码:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.print(request.getAttribute("teamID"));
RequestDispatcher dispatch = request.getRequestDispatcher("/UserPages/UserGetTeam.jsp");
dispatch.forward(request, response);
}
并打印出“null”......
有什么问题? 我正在使用github,在这个项目中,这个代码几个小时前就已经运行了,但现在它没有,没有人改变/提交这个特殊的servlet或jsp ...
答案 0 :(得分:2)
您在网址中传递的内容是参数,而不是属性。参数和属性不同
你应该使用
request.getParameter("teamID");
区别在于
request.getAttribute()
返回一个Object,request.getParameter()
返回String