Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Advanced
Mar 6, 2003

Set Attributes in a Servlet Request


Usually, you set attributes in a session and the attributes are available through out the session. If you want to limit the scope of an attribute to just a request, you can set the attributes on a request object. This is how:
 
request.setAttribute("attributeName",attributeValue);

attributeName - This is a string , the names starting with java., javax.,
sun., com.sun. are reserved names.
attributeValue - This is any object.

You can forward this request to other servlets or jsps using requestDispatcher and make the attributes available there.

You can get the attributes in the target servlet/jsp using:
 
getAttributeNames();
getAttribute("attributeName");

Thus, you can increase the functionality of your request object not just by limiting it to get parameters, which is a normal practice. This also helps in reducing the load on session.
Ram Dhan
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap