What is the difference between getAttribute() and getParameter() of jsp?

Asked 2 years ago, Updated 2 years ago, 55 views

When coding the jsp server side, I usually use the getParameter method to call the print message of request. I wonder the difference between getParameter and getAttribute. Thank you.

jsp

2022-09-22 21:10

1 Answers

getParameter is used to extract the values contained in the client request.

http://getParameter.com/hellp?name=1

getAttribute is the value set on the server that can be used within the same request. It is used to refine and deliver values to be delivered to the view, such as the controller servlet.

// in servlet 
request.setAttribute("user_vector", Arrays.asList(3, 4, 2, 1));

// // in jsp
Object vector = request.getAttribute("user_vector");


2022-09-22 21:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.