• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between a Attribute and a Parameter

 
Rishi M
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below are the 4 functions taken from the API of Interface ServletRequest.
My question is what is the difference between a Attribute and a Parameter ? I am talking in perspective of Servlets.
functions are :
1.getAttribute(java.lang.String�name)
2.�java.util.EnumerationgetAttributeNames()
3.�java.lang.StringgetParameter(java.lang.String�name)
4.�java.util.EnumerationgetParameterNames()
��

Thanks,
Rishi
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is actually a pretty important questions, and has been asked in this forum many times. I can sum up the major diferences, but you should do a search to find out more. Basically, Parameters are Strings, and generally can be retrieved, but not set.

Attributes are objects, and can be placed in the request, session, or context objects. Because they can be any object, not just a String, they are much more flexible. You can also set attributes programaticly and retrieve them later. This is very useful in the MVC pattern.

If you are still unclear after searching, post again, and I can try and help more.
[ December 05, 2005: Message edited by: Paul Bourdeaux ]
 
Rishi M
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot !
Just to share with all.
This was the response which i got from my friend regarding this :

FOr data sent by HTML form Always do a request.getParameter to extract request parameters (i.e. data sent by posting a html form ).so when you do a post from html, data can be automatically retrieved by using getParameter.

Always use request.getAttribute to get an object added to the request scope on the serverside i.e. using request.setAttribute.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic