File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Difference between attributes and parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Difference between attributes and parameter" Watch "Difference between attributes and parameter" New topic
Author

Difference between attributes and parameter

sarang bharambe
Ranch Hand

Joined: Apr 01, 2005
Posts: 40
hello Everbody,

Can someone tell me ......

1.The exact difference between attributes and parameters
in regard with servlets?

2.Also if i set the attributes by using setAttribute in a servlet and get it back by using getAttribute in a jsp/servlet then are they completely removed?
3.Or are they available in other jsp's/servlets?
4.Is this thing depend on the scope(session/request etc) for which attributes are set?

Thanks in Advance



SCJP 1.4 (86%)<br />SCWCD 1.4 (86%)<br />----------<br />If You dont succeed at first time,call it Version 1.0 !!!
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

getParameter returns the value of the HTML Form or Querystring parameters as a string. You don't set them on the server side (for the most part).

The getAttribute and setAttribute methods allow you to bind and retrieve objects to the desired scope.

No, calling getAttribute doesn't remove it from that scope.

And no, the behaviour doesn't vary among the different scopes.
The lifecycle of the different scopes DOES vary and this can affect the availablility of an object bound to that scope.
For instance, if you bind an object to request, you won't be able to retrieve it after that request cycle is complete (from another request).


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
1. request parameters are set when the servlet container analyzes the request before your code sees it, and can not be changed. request attributes can be attached to a request by your code.
2. getAttribute gets a copy of a reference to an object - reading the API will reveal that there is a specific removeAttribute method
3,4. request attributes are attached to a request and have no meaning beyond a single request-response cycle. See the HttpSession documentation for session scope attributes
Bill
sarang bharambe
Ranch Hand

Joined: Apr 01, 2005
Posts: 40
Thanx to u guys

This clears the confusion......



 
 
subject: Difference between attributes and parameter