my dog learned polymorphism*
The moose likes Servlets and the fly likes setParameter() and setAttribute() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "setParameter() and setAttribute()" Watch "setParameter() and setAttribute()" New topic
Author

setParameter() and setAttribute()

Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
Hello Folks,
Normally, getParameter() and setParameter() are used to retrieve information posted by a form using GET/POST.Information posted with form can be retrieved with getAttribute.BUT ONLY if the information is explicitly put in objects like request, pagecotext etc using "setAttribute", then we MUST use "getAttribute" NOT *getParameter". I believe information put in these objects with "setAttribute" and "setParameter" are different and eventhough are placed in the same object.Now my question is WHAT is the situation WHERE "setAttribute" is required instead of "setParameter"? and we can't use "setParameter" at all but "setAttribute"? I would appreciate if you could point out clearly.
thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

There is no setParameter() method.

getParameter() is used to retrieve submitted parameter values, be they from a form submission or retrieved from the query string of a URL.

setAttribute() and getAttribute() are used to get and retrieve scoped variables from the page, request, session and application contexts.

They are completely different concepts.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
Hi Bear,
Originally posted by Bear Bibeault:
There is no setParameter() method.

getParameter() is used to retrieve submitted parameter values, be they from a form submission or retrieved from the query string of a URL.

setAttribute() and getAttribute() are used to get and retrieve scoped variables from the page, request, session and application contexts.

They are completely different concepts.


So getParameter() can't be used to get the scoped variables? WHY? because there's not setParameter?

How is parameter different than attribute? specific situation each one is required? thanks.
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Originally posted by Carn Melon:

So getParameter() can't be used to get the scoped variables? WHY? because there's not setParameter?

Why do you need two methods to do the same action?


How is parameter different than attribute? specific situation each one is required? thanks.

parameters are String values bound to String names(keys), are set by the J2EE server, from the HTTP request sent by the browser.
An attribute can be any object bound to a String name(key), you have to explicitly bind it or unbind it.

Have a look at
J2EE API, a programmer's best friend


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
 
Don't get me started about those stupid light bulbs.
 
subject: setParameter() and setAttribute()
 
Similar Threads
uploading and storing image in JSP/Mysql
Select tag
getAttribute(),setAttribute,getParameter,setParameter methods with examples
What is the diff b/w getAttribute and getParameter
Servlet runs, but doesn't do anything