aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Attributes Doubt?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Attributes Doubt??" Watch "Attributes Doubt??" New topic
Author

Attributes Doubt??

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9503
    
    2

Hi Guys,

I'm not able to understand the following question from the HFSJ book!,

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{
req.setAttribute("a", "b");
req.setAttribute("a", "c");
req.setAttribute("a");
}

public void attributeAdded(ServletRequestAttributeEvent ev){
System.out.println("A:" + ev.getName() + "->" + ev.getValue());
}

public void attributeAdded(ServletRequestAttributeEvent ev){
System.out.println("M:" + ev.getName() + "->" + ev.getValue());
}

public void attributeAdded(ServletRequestAttributeEvent ev){
System.out.println("P:" + ev.getName() + "->" + ev.getValue());
}

How will this print A:a->b P:a->b M:a->c??

Please help me guys??

Thanks in advance!


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Micheal John
Ranch Hand

Joined: Nov 01, 2006
Posts: 344

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{
req.setAttribute("a", "b");
req.setAttribute("a", "c");
req.setAttribute("a");
}

public void attributeAdded(ServletRequestAttributeEvent ev){
System.out.println("A:" + ev.getName() + "->" + ev.getValue());
}

public void attributeAdded(ServletRequestAttributeEvent ev){
System.out.println("M:" + ev.getName() + "->" + ev.getValue());
}

public void attributeAdded(ServletRequestAttributeEvent ev){
System.out.println("P:" + ev.getName() + "->" + ev.getValue());
}

How will this print A:a->b P:a->b M:a->c??


If your are taking from HFSJ, then It should be like this:


NO surprise in the o/p:
First your adding the attribute so A:a->b
Then your replacing the value for the same attribute "a", so P:a->b
Finally removing..

I think the problem for you is with P:a->b instead of P:a->c..the getValue() method returns the old value of the attribute if the attribute was replaced
[ January 06, 2007: Message edited by: Micheal John ]

Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9503
    
    2

Michael,

Thanks for the help, I was dubious about the way attributes work with respect to the above question. Could you tell me where I can find a suitable explanation for the question given on that page in the HFSJ book??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Attributes Doubt??