tags:

views:

174

answers:

5

Hi,

Could anyone please clarify the defination of attribute?

for example, in the following code, what is an attribute:

request.setAttribute("ja",new foo.Employee());

Is the attribute in the above code an object of type foo.Employee(), or it is key/value pair, or it is actually "ja"?

+1  A: 

Request attributes are (or at least act like) a map of objects, in this case the key is "ja" and the value is a new foo.Employee.

The session, page, and application have the same data structure.

stevedbrown
+1  A: 

Request attributes are values indexed by a key (in your case "ja") which are shared in the life of the request object. In Java filter, servlet, jsp, include and forward use same request object so for example you can push an object in a servlet and pull it in a JSP.

The same approach is for session and application scopes

victor hugo
A: 

Here an attribute is a custom piece of information (here a new foo.Employee) added to your request (in a Map,Object> . This information will last as long as this request is processed and it can be used later in the process, for example by a JSP.

Pierre
A: 

It's a key value pair From the docs: setAttribute

public void setAttribute(java.lang.String name, java.lang.Object o)

Stores an attribute in this request. Attributes are reset between

requests. This method is most often used in conjunction with RequestDispatcher.

Attribute names should follow the same conventions as package names.

Names beginning with java., javax., and com.sun.*, are reserved for use by Sun Microsystems. If the value passed in is null, the effect is the same as calling removeAttribute(java.lang.String).

nos
+1  A: 

From the servlet API specification:

Attributes are objects associated with a request. Attributes may be set by the container to express information that otherwise could not be expressed via the API, or may be set by a servlet to communicate information to another servlet (via the RequestDispatcher). Only one attribute value may be associated with an attribute name.

dfa