Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Some help with a sample SCWCD question based on Listeners.

 
Abhijit Ghatnekar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm very much confused by the following question and it's answer. It's a program actually.

Assume the below to be a valid HTTP Servlet that has been registered with a HTTPServletRequestAttribute Listener class.



And the output is this..

=======================
A:a->b P:a->b M:a->c
=====================

Now how is it that we get the old value of the attribute "a" even if we replace the value of the attribute a?
Is there a way, I could get the new, latest value of "a" the moment it is replaced? This could lead to a potential bug in a production code, not sure why it has to work like this.

Any thoughts?

Regds,
Abhijit.
 
Roel De Nijs
Sheriff
Posts: 10763
148
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please QuoteYourSources
 
Ankur Gargg
Ranch Hand
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI

You can use ev.getServletRequest().getAttribute("a") to get the new value thus the getValue() method has been coded to return the old value.


Regards
Ankur Garg
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!