What is the difference between getAttribute()
and getParameter()
methods within HttpServletRequest
class?
-getParameter() :
<%
String sValue = request.getParameter("testParam");
%>
<%= sValue %>
request.getParameter("testParam")
will get the value from the posted form of the input box named "testParam" which is "Client param". It will then print it out, so you should see "Client Param" on the screen. So request.getParameter() will retrieve a value that the client has submitted. You will get the value on the server side.
-getAttribute() :
request.getAttribute()
, this is all done server side. YOU add the attribute to the request and YOU submit the request to another resource, the client does not know about this. So all the code handling this would typically be in servlets.getAttribute always return object.