KPax
asked on
HttpServlet and ServletRequestAttributeListener explantion
This is from the book I am reading:
And answer is:
And explanation from book is:
My question is how this could be?
Particularly this part of sequence is not clear to me: P:a->b
Why would it be once again P:a->b instead of P:a->c ?
Given this code from an otherwise valid HttpServlet that has also been
registered as a ServletRequestAttributeListener:
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
req.setAttribute(“a”, “b”);
req.setAttribute(“a”, “c”);
req.removeAttribute(“a”);
}
public void attributeAdded(ServletRequestAttributeEvent ev) {
System.out.print(“ A:” + ev.getName() + “->” + ev.getValue());
}
public void attributeRemoved(ServletRequestAttributeEvent ev) {
System.out.print(“ M:” + ev.getName() + “->” + ev.getValue());
}
public void attributeReplaced(ServletRequestAttributeEvent ev) {
System.out.print(“ P:” + ev.getName() + “->” + ev.getValue());
}
What logging output is generated?
And answer is:
C. A:a->b P:a->b M:a->c
And explanation from book is:
Tricky! The getValue method returns the OLD value of the attribute if the attribute was replaced.
My question is how this could be?
Particularly this part of sequence is not clear to me: P:a->b
Why would it be once again P:a->b instead of P:a->c ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER