Difference between getAttribute() and getParameter()

后端 未结 10 2154
情话喂你
情话喂你 2020-11-22 08:44

What is the difference between getAttribute() and getParameter() methods within HttpServletRequest class?

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 09:15

    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.

提交回复
热议问题