aspose file tools*
The moose likes Servlets and the fly likes request.getParameter() vs request.getAttribute() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "request.getParameter() vs request.getAttribute()" Watch "request.getParameter() vs request.getAttribute()" New topic
Author

request.getParameter() vs request.getAttribute()

pankaj kapoor
Greenhorn

Joined: Sep 22, 2005
Posts: 17
Can anybody tell me the difference between request.getParameter() and request.getAttribute().

Thanks in advance
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
A "parameter" is a name/value pair sent from the client to the server - typically, from an HTML form. Parameters can only have String values. Sometimes (e.g. using a GET request) you will see these encoded directly into the URL (after the ?, each in the form name=value, and each pair separated by an &). Other times, they are included in the body of the request, when using methods such as POST.

An "attribute" is a server-local storage mechanism - nothing stored in scoped attribues is ever transmitted outside the server unless you explicitly make that happen. Attributes have String names, but store Object values. Note that attributes are specific to Java (they store Java Objects), while parameters are platform-independent (they are only formatted strings composed of generic bytes).

There are four scopes of attributes in total: "page" (for JSPs and tag files only), "request" (limited to the current client's request, destroyed after request is completed), "session" (stored in the client's session, invalidated after the session is terminated), "application" (exist for all components to access during the entire deployed lifetime of your application).

The bottom line is: use parameters when obtaining data from the client, use scoped attributes when storing objects on the server for use internally by your application only.


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331
Nice explanation!! Thanks


Blog
Kosala W.Abayagunawardene
Ranch Hand

Joined: Dec 15, 2007
Posts: 47

Thanks you saved me lots of time


[SCJP] ::[SCWCD]::[BCS::BIT::SCBCD] - Studying[My Blog]
prasad guna
Ranch Hand

Joined: Feb 12, 2009
Posts: 43




thanks for clear explanatioin...


Prasath.G
SCJP
Tomita Militaru
Ranch Hand

Joined: Jan 16, 2009
Posts: 37
Thank you!


Poor is the man whose pleasures depend on the permission of another.
Sam Veasley
Greenhorn

Joined: Feb 15, 2013
Posts: 5
Exact Explanation...
Thanks a lot...


Thanks & Regards,
Sam Veasley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: request.getParameter() vs request.getAttribute()