Difference between getattribute and getparameter

Source: Internet
Author: User
Tags what parameter

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. request. the data transmitted by the getparameter () method is transmitted from the Web Client to the Web server, representing the HTTP request data; request. the data transmitted by the setattribute () and getattribute () methods only exists in the Web Container and is shared among the Web Components with forwarding relationships. That is, the request. getattribute () method returns objects in the request range, while the request. getparameter () method obtains 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 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. 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 is not used at all. getattribute () request. getattribute () and request. the difference between getparameter () is request. getattribute () obtains the object type, while request. getparameter () is a web application of the string type. As chenshaizi (Chen shaobin) said, it is basically post-based transmission, and the value of getparameter is used. For self-controlled items, you can use request. setattribute and getattribute to implement value transfer.
For the structs framework, getattribute is used a little more. For others, getparameter is basically used. My understanding:
Session. getattribute (); get session
Request. getparameter (); obtain parameter1.getparameter to 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 it getparameter () if the value is not submitted or saved next time, it will not be available after the next redirection?
: 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.

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, I don't want to say anymore. The parameter is generated in HTML like checkbox textfield password radio... value
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.