A confusing question: What is the difference between getparameter and getattribute in JSP?

Source: Internet
Author: User

A confusing question: What is the difference between getparameter and getattribute in JSP?

 

What is the difference between getparameter and getattribute in JSP?
-- To be honest, I was confused for a long time and I knew how to use it. But I was not very clear about the difference. I found a lot of information to understand it. Another friend asked me this question yesterday. I thought I was also confused. So I posted this question to my confused friends.
-- Getparameter is of the string type. Or a http://a.jsp? Id = 123 in 123, or 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.
-- Getparameter () is used to obtain the parameter value passed by post/get;
-- Getattribute () is the value of the session;
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.