• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Attributes vs Parameters

 
Gunnar Maluf
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i have it all messed up. In a servlet i set Attributes with
request.setAttribute("name",value);

In a JSP i get the Attribute with request.getAttribute("name");
BUT if i get the Attribute with request.getParameter("name") it works!

I know that one gives me an Object and the other give me an String.

Someone can explain to me the difference between them besides the return type? I dont get it how it works...

Regards
Gunnar
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parameters (usually) represent the values that were posted by the client (usually a browser). therefore they are Strings (http post sends information in the form of a String - name/value pairs).

Attributes are added server side so they are added as objects with a String as a key (think Hashmap or Hashtable)
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the URL in your browser right now. See the things after the question mark? Those are parameters. In GET requests they are in the URL and in POST requests they are in the body. They are usually all the little values that get submitted with a form. They are Strings because they are text passed from the browser to the server.

Attributes, on the other hand, are just a special way to keep track of objects on the server side.
 
Gunnar Maluf
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your help but i still dont get it why if i do a getParameter("foo") (having the foo set through request.setAttribute("foo",42)) works. I know theres not a setParameter() method...but the way i understand parameters and attributes should be in a different "place" in the app.

regards
Gunnar
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If getParameter("name") works, then name was a part of the submitted URL or part of a submitted form.

The only other possibility involves craziness with an Intercepting Filter plus a Request Wrapper... but I seriously, seriously, seriously doubt this to be your case.
 
Gunnar Maluf
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a small test here at home with another servlet and indeed it did not work. I will look into the code on monday and post it here or look at it again to make sure i got what happened right.

regards
Gunnar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic