Servlet attribute


What is servlet attribute


servlet Attributes are Objects inside the server for common sharing within the scope.
servlet Attribute Scopes are:-

1.Request: The request attribute can be accessible within that same servlet Request.

2.Session: these attributes are accessible within the same Http Session.

3.Context /Application: any servlet within the same application can have access to context attributes.


Attributes are the objects that can be used to set, get or delete (removed) from one of the following scopes:
*application scope
*session scope
*request scope
The Servlet attribute is used mainly to pass the information from one servlet to another or from one filter to another, etcetera. It is just like passing an object from one class to another so that we can reuse the same object again and again.

*Some common public methods of servlet attributes are:

*Object getAttribute(String name)
Returns the attribute object for the specified name.

*void setAttribute(String name, Object object)
Sets the given object in the application scope.

*Enumeration getInitParameterNames()
Returns the names of the context’s initialization paramters as an Enumeration of String objects.

*void removeAttribute(String name)
Removes the attribute with the given name from the servlet context.