Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get servlet name from ServletRequestAttribute Listener

 
liao Yang
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know which servlet is the attribute notification about, but can't find a way to do it.

Please help i this case.

Thanks

Liao
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no guarantee that the request attribute is even being set by a Servlet. Filters are allowed to set request attributes too, you know.
 
liao Yang
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marc,

Thank you for the reply.

In the following example, I registered the listener in the DD and I did get the notifications of attribute changes.

I'd like to know the servlet whose attribute is added/removed/replaced. Acoording to your reply, there is no way to do that. Is my understanding correct?

Thanks

Liao

public class MyServletRequestAttributeListener implements ServletRequestAttributeListener {
/*
** ServletRequestAttributeListener
*/
public void attributeAdded(ServletRequestAttributeEvent event) {
System.out.println("ServletRequestAttributeListener.attributeAdded()");
displayInfo(event);
}

public void attributeRemoved(ServletRequestAttributeEvent event) {
System.out.println("ServletRequestAttributeListener.attributeRemoved()");
displayInfo(event);
}

public void attributeReplaced(ServletRequestAttributeEvent event) {
System.out.println("ServletRequestAttributeListener.attributeReplaced()");
displayInfo(event);
}

private void displayInfo(ServletRequestAttributeEvent event) {
System.out.println("Source servlet: " + event.getSource().toString());

String attrName = event.getName();
String attrValue = (String)event.getValue();
System.out.println(attrName + ": " + attrValue);
}
}
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't believe there is a way, but you could do:
((HttpServletRequest)event.getServletRequest()).getServletPath();
which is about the next best thing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic