Links and differences between Request.setattribute (), Session.setattribute () and Request.getparameter (), Request.getattribute ()

Source: Internet
Author: User

Paired with 1.session.setattribute () and Session.getattribute (),scope is the entire session,Use this data on all pages。 Paired with 2.request.setattribute () and Request.getattribute (),scope is between the request and the requested page。 Request.setattribute () isuse only when the next forward of this action is needed; Request.getattribute () represents the property that is set from the request scope,You must setattribute set properties before you can get them through getattribute, set with the type of object that was obtained. In fact, the name and value of object in the form control are stored in aHash Table, so here the name of object is given to the hash table to find the value corresponding to it. The arguments for SetAttribute () are string and object. 3.Request.getparameter () is the parameter that receives the parameter and the parameter is the page submission。 Include: Parameters for form submission, URL rewriting (that is, ID in xxx?id=1), and so on, so this method does not have a parameter set (no Setparameter ()), and the receive parameter returns not an object, but a string type. difference between 4.request.getparameter () and Request.getattribute () (1)Request.getparameter () is obtained through the implementation of the container to obtain the data passed through similar post,get, Request.setattribute () and getattribute () just flow inside the Web container, Only the request processing phase. (2)the data passed by the Request.getparameter () method is uploaded from the Web client to the Web server side and represents the HTTP request data. The Request.getparameter () method returns data of type String.the data passed by the Request.setattribute () and GetAttribute () methods only exist inside the Web container and are shared between Web components that have a forwarding relationship。 The Request.getattribute () method returns the object that exists in the request scope, and the Request.getparameter () method is to get the data submitted by HTTP. And one more thing,HttpServletRequest class with SetAttribute () methodWithout the Setparameter () method. Other than thatyou can send a Receive object with Setattribute,getattribute. And GetParameter obviously can only pass strings. SetAttribute isThe application server places this object in the same piece of memory as the page, and when your page server redirects to another page, the application server copies the memory of the other page. So getattribute can get the value you set., of course, this method can be used to pass objects. The session is the same, except that the object's life cycle in memory is different. GetParameter is just the application server when you analyze the text of the request page you sent up, get the value that you set on the form or URL redirection. Also, GetParameter returns a string that reads the value from the submitted form, GetAttribute returns an object, needs to be converted, can be set to any object using setattribute, and is flexible to use at any time;

Links and differences between Request.setattribute (), Session.setattribute () and Request.getparameter (), Request.getattribute ()

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.