aspose file tools*
The moose likes Servlets and the fly likes servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet" Watch "servlet" New topic
Author

servlet

jaffrin abdul salam
Greenhorn

Joined: Sep 16, 2005
Posts: 23
Hi everyone,

Public void doget(HttpServletRequest req,HttpservletResponse res)
{
req.setAttribute("a","b");
req.setAttribute("a","c");
req.removeAttirbute("a");
}
public void attributeAdded(ServletRequestAttributeEvent ev)
{
System.out.pritnln("A:" + ev.getName() +"->"+ev.getValue());
}
public void attributeRemoved(ServletRequestAttributeEvent ev)
{
System.out.pritnln("M:" + ev.getName() +"->"+ev.getValue());
}
public void attributeReplaced(ServletRequestAttributeEvent ev)
{
System.out.pritnln("P:" + ev.getName() +"->"+ev.getValue());
}


The output of the above code is
A:a->b P:a->b M:a->c


I have question on this getValue method.
Why this getValue method returns the OLD value of the attribute if the attribute was replaced?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

jaffrin,
Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here. In particular, please see UseAMeaningfulSubjectLine
.


That you posted in a 'Servlets' forum is enough for us to know that your question is about servlets. The subject line "servlet" gives us no hint as to the nature of your question.

Again, welcome to JavaRanch and good luck with your question.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
From the API:
"Returns the value of the attribute that has been added removed or replaced. If the attribute was added, this is the value of the attribute. If the attribute was removed, this is the value of the removed attribute. If the attribute was replaced, this is the old value of the attribute."

My feeling is that since getValue() returns the most recent attribute value, when an attribute is added or removed, I suspect that the API developers decided that if an event notification was going to be generated when the value is replaced it might be wise to be able to get the value of the
attribute before it was replaced.

Note that if you need to get the new value of the request attribute, ServletRequestAttributeEvent inherits a getServletRequest() method which can then be used to get at the attribute's current (NEW) value.

Hope this helps!
 
jQuery in Action, 2nd edition
 
subject: servlet
 
Similar Threads
Doubts in Mock exam HFSJ
getValue() method
page no 218 from KathySierra bookabout attributes
page 218 Head First Servlets and JSP
Attributes Doubt??