difference between request.getParameter() and request.getAttribute()

What is the difference between request.getParameter() and request.getAttribute()?

I too have another doubt in session. What is the difference between session.getValue() and session.getAttribute()?


The difference between getAttribute and getParameter is that getParameter will return the value of a parameter that was submitted by an HTML form or that was included in a query string. getAttribute returns an object that you have set in the request, the only way you can use this is in conjunction with a RequestDispatcher. You use a RequestDispatcher to forward a request to another resource (JSP / Servlet). So before you forward the request you can set an attribute which will be available to the next resource. Does this make sense?



I had a look at the API docs for session.getAttribute() and getValue() and saw that getValue is deprecated and getAttribute should be used in its place, so rather use getAttribute. Although it seems like they achieve the same result. I personally have never used getValue.

你可能感兴趣的:(html,jsp,servlet)