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.