2 Answers

0 votes
setAttribute(String name, Object value) of HTTPSession object binds an object to this session, using the name specified and can be used to update an attribute in session.
answered Jun 30, 2016 by Narayana
0 votes

An attribute in servlet is an object that can be set, get or removed from one of the following scopes:

  1. request scope
  2. session scope
  3. application scope

The servlet programmer can pass informations from one servlet to another using attributes. It is just like passing object from one class to another so that we can reuse the same object again and again.

Attribute specific methods of ServletRequest, HttpSession and ServletContext interface

There are following 4 attribute specific methods. They are as follows:
  1. public void setAttribute(String name,Object object):sets the given object in the application scope.
  2. public Object getAttribute(String name):Returns the attribute for the specified name.
  3. public Enumeration getInitParameterNames():Returns the names of the context's initialization parameters as an Enumeration of String objects.
  4. public void removeAttribute(String name):Removes the attribute with the given name from the servlet context.
answered Jan 2, 2017 by Roshan333

Related questions