Difference between getattribute getparameter

Source: Internet
Author: User
Tags what parameter

There are a lot of information on the Internet, but they are all chaotic. Record points are used as a reference.

Difference between getattribute and getparameter 1. getattribute is the attribute set by setattribute in JSP.
2. What parameter gets is string; what attribute gets is object.
3. The data transmitted by the request. getparameter () method is transmitted from the Web Client to the Web server, representing the HTTP request data;
The data transmitted by the request. setattribute () and getattribute () methods only exists in the Web Container, between the Web Components with forwarding relationships.
Share. That is, the request. getattribute () method returns objects in the request range, while the request. getparameter () method is
Obtain the data submitted by HTTP.

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 Http://a.jsp? Id = 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 receiveProgramThe value passed by 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
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.

Getparameter returns a string to read the value in the submitted form;
Getattribute returns an object that requires conversion. You can use setattribute to set it to any object. It is flexible to use and can be used at any time;

 

I personally think:
Request. getattribute (): the value of the variable set during request. Use request. setattribute ("name", "your own value"); To set the value,
Request. getparameter (): extract the sent parameters, such as: this page
Http://community.csdn.net/Expert/topic/4633/4633804.xml? Temp =. 3488123.
Request. getparameter ("Temp") = ". 3488123"

Request. getparameter
Is used to accept parameters from the get or POST method
<Form method = post>
<Form method = get>
<A href = "1.jsp? Id = 1 "> OK </a>
Only java. Lang. string can be accepted.
That is, string parameter _id = request. getparameter ("parameter _id ");
Request. getattribute
Is used to accept variables or actions from servlet (in fact, action is a special servlet)
In action, request. setattribute ("RET", RET );
Only java. Lang. object can be accepted.
That is, list ret = (list) request. getattribute ("RET ");
If you only use JSP, request. getattribute () is not used at all ()

The difference between request. getattribute () and request. getparameter () Is that request. getattribute () obtains the object type, while request. getparameter () obtains the string type.

 

For general web applications, as Chen shaizi (Chen shaobin) said, it is basically post-based transmission and getparameter is used. For self-controlled items, you can use request. setattribute and getattribute to implement value transfer.
For structs frameworks, getattribute is used a little more. For others, getparameter is basically used.

My understanding:
Session. getattribute (); get session
Request. getparameter (); get Parameter

1. getparameter can obtain the parameter value sent from the client to the server.
Getattribute can get the parameter value set by setattribute, which is equivalent to using getattribute to get a custom parameter instead of the parameter obtained from the client.
2. getparameter can only pass string-type variables. getattribute can pass vector.

 

Getparameter (), get the form value getattribute () to get the session Value
Getparameternames () obtains an array of parameters in a form or URL.
Getattributenames (): returns the names of all attributes of the request object. The result set is an instance of the enumeration (enumeration) class.

Based on the information above, is the value obtained by getparameter () not submitted or saved next time?
: Correct
Can the property value obtained by getattribute () still be retrieved after redirection because it exists in the session?
Getattribute () is available in both request and session, but has different scopes. It must be stored somewhere before it is retrieved. This kind of stuff can access objects.

Haha

Http://community.csdn.net/Expert/topic/4763/4763471.xml? Temp =. 1793177.

See the following? Temp =. 1793177 No ,? You can use request. getattribute ("Temp") to obtain the string ". 1793177 ",
Before getattribute (), you must set serattribute () in the page or logic for use. It is clear that I will not talk about it anymore.

 

Parameter is the value generated in HTML like checkbox textfield password radio...
Getattribute is the attribute set by setattribute in JSP. And ....
Parameter returns string
Attribute obtains the object

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.