0

in some.jsp i have this code:

<%
            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>
                <%
            }
        %>

and it makes its job ... (I've checked with out.print and every single teamID has its unique value);

in UserGetTeam (servlet) I have this code:

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);
}

and it prints out "null"...

what's the problem? i'm working on github, on this project, this code was working several hours ago, but now it doesn't and nobody has changed/commited this particular servlet or jsp...

Giorgi Margiani
  • 292
  • 1
  • 6
  • 17

1 Answers1

2

What you are passing in the url is a parameter and not an attribute. Parameters and attributes are different

You should use

request.getParameter("teamID");

The difference is

  1. request.getAttribute() returns an Object and request.getParameter() returns String
  2. Generally, parameters are sent from client, i.e. jsp and attributes are set and used at server side, e.g. setting an attribute in the session and using it.
Prasad Kharkar
  • 13,410
  • 5
  • 37
  • 56