Forums Register Login

Difference between getAttribute and getParameter

+Pie Number of slices to send: Send
Hi Team

i have a very basic doubt in servlet. what is the differnce between getAttribute and getParameter.
what are all the situations where we are using both of them?
+Pie Number of slices to send: Send
getAttribute() is used to fetch scoped variables.

getParameter() is used to fetch request parameters from the GET query string or POST body.
+Pie Number of slices to send: Send
getAttribute() is used to retrieve objects which are stored in the request, session or application context scopes of the application using setAttribute()
+Pie Number of slices to send: Send
Then, getAttribute() is used in the JSP page to get the results that are set into a scope(request, session...) and getParameter() is used to get the values we are getting from a JSP page.

Am I right?
+Pie Number of slices to send: Send
Just like Bear Bibeault said:

getAttribute() is used to fetch scoped variables.

How you scope them? In a serlvet you do request.setAttribute("attrName", attrValue); So you can only use it within the same request. For example, in a servlet you retrieve some data from database, a record, you "scope it" as request attribute, and if your servlet is forwarding the request to another servlet or jsp, you can continue using that scoped attribute.

getParameter() is used to fetch request parameters from the GET query string or POST body.

a) You use it when you need to retrieve params from the query string, for example: http://hellou.mx?param1=hola¶m2=amigos, request.getParameter("param1") will give you back "hola".
b) You can use it to retrieve params comming from a post (for example, when user submitted an application/x-www-form-urlencoded form).
+Pie Number of slices to send: Send
Thank You all.
now I got an idea..
+Pie Number of slices to send: Send
Thank You all.
now I got an idea..
+Pie Number of slices to send: Send
the explanation is really good
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1184 times.
Similar Threads
getParameter,getAttribute
difference between getParameter() and getAttribute()
Difference between getParameter() and getAttribute()
getParameter()
What is the diff b/w getAttribute and getParameter
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:44:35.