This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parameter versus attributes

 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CAn anyone please explain me the exact difference between parameter and attributes. Is it only "init" and "context" parameters come under parameter.

ex in jsp we have say,
<input type="text" name="n1"/>

then the servlet will extract it as

String x=request.getParameter("n1");

i guess above is correct?. But i want to know where to use parameter or an attribute
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will try to explain, sorry my english.

The concept or the theory, is almost equals. (for some situations)

Parameters, are for a configurations of something, I mean, think about on certain behavior, that mean, that you can use parameters for a data base behavior, maybe you configure a parameter, for a a data base in particular, but maybe, another day you can configure that parameter for another database... i dont know if you see the point.

The attributes are most for sharing information on the application, for example, for share information, maybe you want share the name of the user logged, to another component (jsp/servlet), you can give me?

That is my point of view.
 
Joy Mukherjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe be you are mixing with initparamters and parameters (request parameters)
Both of them are String.
Init Parameters are of 2 types
Context Init Paramters:
Servlet Init Parameters: Both uses the method getInitParameter(String name)
Normal paramters example form paramters : Accessor method is getParameter(String)

Attributes are objects and can be put into session,request and context

methods are
setAttribute(String name,Object attr);
Object getAttribute(String name);

Thanks and Regards
Joy
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to summarise what has been said above, for the purposes of SCWCD:

parameter = a read-only String property (set by client in request, or in app. configuration, e.g. in the DD)

attribute = an Object stored in a scope (by the application, or possibly implicitly by the container)

The method names mostly reflect this convention.
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the info
 
Atul Samnerkar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
============================================================================
Basic Difference which has already mentioned in this trail..
- Parameters are either of String or String[] type. Mostly it is not set by the Developer.
- Attribute is of Object type. You always need to cast it before usage. It is always set and used by Developer.
============================================================================
Parameters are catagorized in 2 forms

1. Parameters
1a. Request Parameters - query String (Get) / request body (Post)
1b. include/forward request using jsp aram - Code**
** this is the only place, from where parameters can be set / added by
Developer.

2. Init Parameters
2a. Servlet Init Parameters - DD
2b. Context Parameters - DD

Attributes can be set and retrieved only from the Code. So attributes are always controlled by Developer. ============================================================================
You can also refer to Page 186 of HFJS 2nd Edition.
============================================================================

Cheers...
Atul Samnerkar
[ September 28, 2008: Message edited by: Atul Samnerkar ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic