What is the difference between getParameter and getAttribute in JSP?

Source: Internet
Author: User
-- GetParameter is of the String type. OrHttp://a.jsp? Id = 123Or the data submitted by a form.
-- GetAttribute can be an object.
-- GetParameter () is used to obtain the parameter value passed by POST/GET;
-- GetAttribute () is used to obtain the data value in the object container;
-- GetParameter: used for client redirection, that is, when a link is clicked or a button is submitted for value transfer, it is used to receive data when a form or url is redirected for value transfer.
-- GetAttribute: used for server redirection, that is, the forward function is used in the sevlet, or the mapping. findForward function is used in struts. GetAttribute can only receive values transmitted by the program using setAttribute.
In addition, you can use setAttribute and getAttribute to send the receiving object, while getParameter can only transmit strings.
SetAttribute indicates that the application server places this object in the memory of the corresponding page. When your page server redirects to another page, the application server copies the memory to the memory corresponding to another page. In this way, getAttribute can get the value you set. Of course, this method can be used to transmit objects. The same is true for sessions, but the lifecycle of objects in the memory is different.
GetParameter is only used by the application server to analyze the text of the request page you sent, and obtain the value you set when you set it to form or url redirection.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.