Why does getAttribute() in HttpServletRequest works for GET method but not for POST method?

You should always use getParameter, when attribute come from GET or POST method. And use getAttribute when request is forwarded from another servlet/jsp. Such as :

ServletA:
request.setAttribute("test","value")
request.getRequestDispatcher("/ServletB").forward(request, response)


ServletB:
request.getAttribute("test") <-- you can get test attribute by using getAttribute

Leave a Comment