Difference between getParameter and getAttribute in JSP

Source: Internet
Author: User

Getparameter returns a string used to read the values in the submitted form. (page parameters and strings) such? Id = 123.
The object returned by getattribute must be converted. You can use setattribute to set it to something that is flexible and can be used at any time. It is often used to pass parameters to jsp through servlet pages.
Getparameter () is to get post -- getattribute () is to get the data value in the east-west container;
-- Getparameter: used for client redirection, that is, when the link is clicked or the button is submitted, the value is used, that is, the data is used when the form or url is redirected to transfer the value.
-- 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 the value from setattribute.
-- Getparameter () is used to obtain post -- getattribute () is used to obtain the session value;
In other words, you can use setattribute and getattribute to send and absorb data. While getparameter can only transmit strings.
Setattribute is used by the app server to place this item in the memory corresponding to the page. When your page is directed to another page, the app server will copy this memory to another page
If you use getattribute in the memory, you can obtain the value you set. Of course, this can be used to transmit things. The same is true for sessions, but the lifecycle of things in the memory is different.
Getparameter is only used by the application server to obtain the value you set for form or url redirection when interpreting the text of the request page you provided.

Personal Opinion:

Http:

The request has a smaller range. It is just a request. Simply put, it is an operation on the page. request. getParameter () is used to obtain parameters from the url and form on the previous page. However, if a request involves multiple classes,
You can use request. setAttribute () and request. getAttribute () parameters later. However, after the result is output, the request is complete. Only java. lang. string
That is to say, string response _id request. getattribute
Is used to take variables or actions from servlet (the actual action is a special servlet)
In action, request. setattribute (can only serve java. lang. object
That is to say, if you only use jsp for list ret, you cannot use request. getattribute ()
Indicates the HTTP request data. The request. getParameter () method returns String-type data.

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.